gpt4 book ai didi

html - 具有填充内容(高度)的CSS布局

转载 作者:行者123 更新时间:2023-11-28 14:17:50 24 4
gpt4 key购买 nike

我不太擅长 CSS,我正在尝试弄清楚如何为我需要调整的网站执行以下操作:

container_div(directly under body) 100% height (body 也是 100% height), header 170px height, 然后是 content div (应该从 bottom header 向下延伸到), footer div with copyright notice 50px高度。

在内容中应该有一个左右div(两个position:relative; float :右/左;)

几乎是这样的:yet another HTML/CSS layout challenge - full height sidebar with sticky footer

但是内容应该溢出:隐藏(我使用自定义滚动条脚本)

我不知道的部分是如何让内容 div(在页眉和页脚 div 之间)包含剩余的高度。

我试过将背景添加到 100% 高度的容器中,但由于我的页眉和页脚是透明的,您可以通过它们看到内容的背景,这很丑陋。

有人可以使用标准模板向我推荐正确的方向吗?剩下的我自己解决。

内容 div 的 CSS 代码也可以(对其余 css 进行一些解释)

编辑:

这样我们就可以使用一些东西(这更容易回答我的问题)

    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> 

<HTML xmlns="http://www.w3.org/1999/xhtml">
<HEAD>
<META http-equiv="Content-Type" content="text/html; charset=utf-8" />
<TITLE>stretchy footer</TITLE>
<LINK rel="stylesheet" type="text/css" href="index.css" />
</HEAD>

<BODY>
<DIV id="container">

<DIV id="header">
<IMG src="./image/header2.png">
</DIV>


<DIV id="left">
<DIV id="content">
This is the div which needs to be stretched between header and footer.
</DIV>
test<BR>
test<BR>
test<BR>
test<BR>
test<BR>


</DIV>

<DIV id="right">
t
</DIV>

</DIV>
</BODY>
</HTML>

CSS 样式:

    /*          <GENERAL>           */
/* cross-browser reset stylesheet */
* { margin: 0; padding: 0; border-style: none;}

*:hover, *:active, *:focus {
outline: 0;
}

html {
filter: expression(document.execCommand("BackgroundImageCache", false, true));
line-height: 1;

-moz-user-select: none;
-moz-user-select: -moz-none;
-webkit-user-select: none;
-khtml-user-select: none;
user-select: none;
-webkit-min-device-pixel-ratio:0;
height: 100%;}
body {height: 100%;} /* safe crossbrowser font */
a {text-decoration: none; outline: none;}
a:active {
border: none;
outline: none;}
.imagewrapper img {
display: inline-block;
width:100%;
-ms-interpolation-mode:bicubic;
image-rendering:-webkit-optimize-contrast;
image-rendering:-moz-crisp-edges;
image-rendering: optimizeQuality;
zoom:1; *display: inline;}
/* </GENERAL> */


.clear {
clear: both; /* deze class gaan we gebruiken om de twee floats #left en #right te clearen. */
}

#container {
height: 100%;
width: 1018px;
margin: 0em auto -10em auto;

position: relative;}



#left {
display: inline-block;
float: left;
height: 100%;
width: 950px;
padding: 0em 2em 0em 1em;
border: 1px solid brown;
background: url(./image/main.png);
}
#left p {
text-align: justify;}


#right {
float: right;
width: 14px;
border: 1px solid red;
}

最佳答案

有多种方法可以使用 CSS 来帮助布置您的 Div。考虑到 float :左/右和position:relative,您在正确的页面上。我想要完全回答您的问题,我需要了解以下内容:

你是给 Div 一个最小高度还是你只是想让它缩放到内容的大小?

如果您使用外部 div 作为主要空间持有者,然后用“position:relative;”的内部 div 填充它们和“ float :左/右”(无论您需要什么)然后您的页面主体将拉伸(stretch)到添加的内容的大小。如果您有最大高度并添加了一些滚动条功能,我们需要知道该滚动条工具是否有自己的高度设置(它是自己的 div/面板吗?)。

还有一点要补充的是,当使用 float 时,您需要包含一个带有 clear:both 作为样式的 div。这样可以正确换行。在要创建换行的任何元素行之后使用它。请务必检查 IE 和 Firefox,因为它们的行为不同......并且忘记了 <div class="clear" runat="server">元素将使页面看起来很有趣。 “清晰”类的 CSS 在这里:

.clear
{
clear:both;
}

我在第一次弄清楚这些东西时使用了这些链接:

CSS 位置:http://www.barelyfitz.com/screencast/html-training/css/positioning/

CSS 高度:http://v1.reinspire.net/blog/2005/10/11/css_vertical_stretch/

请注意,IE 和其他浏览器有所不同。并非所有浏览器都完全支持像 height="auto"这样的属性,因此您需要考虑到这一点。

最后,如果你想让东西拉伸(stretch),你可能需要尝试使用 width 属性(例如 height=99%)。通常我只是让页面主要内容部分的高度由内容决定。我将页面的所有“正文”部分(不是 html 正文,而是主要内容和任何列)包装在一个具有相对位置的 div 中,如果我有一个左列或右列的元素少于主要部分,则设置所有to height = inherit ... or height = 100/99% 应该可以工作,但你需要根据你正在做的事情来玩弄它以获得浏览器中性渲染可能与你元素中的样式有关正在添加。

关于html - 具有填充内容(高度)的CSS布局,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8879447/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com