动态高度div
请参阅以下代码:
<div id="content">
<div id="firstrow">
</div>
<div id="secondrow">
<div class="newsrow"> </div>
<div class="mediarow"> </div>
</div>
<div id="thirdrow">
</div>
</div>
<div id="footer">
<ul>
<li>Home</li>
<li>Link1</li>
<li>Link2</li>
</ul>
</div>
<div id="lastpart">Copyright 2004 - 2011 © example.com , All rights reserved. </div>
为了简单起见,我删除了 firstrow
、newsrow
、mediarow
和 thirdrow
的所有内容。这是我的 css:
#content{
width:1250px;
position: relative;
top: 0px;
margin: 0 0 0 0;
padding: 0 0 0 0;
background: url("imgbg_body_03.png");
right: 66px;
height:2550px;
}
#firstrow{
margin: 0px 20px 0 0;
width:195px;
float:right;
}
#secondrow{
background-color:#772255;
width:740px;
float:right;
}
.newsrow{
width:366px;
float:right;
margin: 2px 2px 2px 2px;
text-align:right;
color:#660066;
/*font:bold 16px Arial;*/
}.mediarow{
/*background:url('imgbg_index_01.png');*/
width:366px;
float:right;
margin: 2px 2px 2px 2px;
}
#footer{
background: url("imgbg_body_02.png");
width:1250px;
height:38px;
position: relative;
top: 0px;
right:66px;
margin: 0 0 0 0;
padding: 0 0 0 0;
}
#footer ul{
margin: 0px 0 0 0;
padding: 5px;/* 0 0 0;*/
}
#footer ul li{
list-style-type:circle;
display:inline;
color:white;
margin : 0 35px 0 35px;
font:bold 12px Tahoma;
}
#footer ul li:hover{
color:#FFFF00;
}
#lastpart{
width:1250px;
position: relative;
top: 0px;
margin: 0 0 0 0;
padding: 20px 0 0 0;
background: url("imgbg_body_04.png");
right: 66px;
text-align:center;
font-weight:bold;
color:#660033;
height:56px;
direction: ltr !important;
}
我的问题是我希望 id content
的 div 根据其中最大的 div 变长或变短。我尝试了 Height
的所有可能值,但是没有人有用。我该怎么办?
提前致谢。
See this code:
<div id="content">
<div id="firstrow">
</div>
<div id="secondrow">
<div class="newsrow"> </div>
<div class="mediarow"> </div>
</div>
<div id="thirdrow">
</div>
</div>
<div id="footer">
<ul>
<li>Home</li>
<li>Link1</li>
<li>Link2</li>
</ul>
</div>
<div id="lastpart">Copyright 2004 - 2011 © example.com , All rights reserved. </div>
I deleted all contents of firstrow
,newsrow
,mediarow
and thirdrow
for simplicity. here is my css:
#content{
width:1250px;
position: relative;
top: 0px;
margin: 0 0 0 0;
padding: 0 0 0 0;
background: url("imgbg_body_03.png");
right: 66px;
height:2550px;
}
#firstrow{
margin: 0px 20px 0 0;
width:195px;
float:right;
}
#secondrow{
background-color:#772255;
width:740px;
float:right;
}
.newsrow{
width:366px;
float:right;
margin: 2px 2px 2px 2px;
text-align:right;
color:#660066;
/*font:bold 16px Arial;*/
}.mediarow{
/*background:url('imgbg_index_01.png');*/
width:366px;
float:right;
margin: 2px 2px 2px 2px;
}
#footer{
background: url("imgbg_body_02.png");
width:1250px;
height:38px;
position: relative;
top: 0px;
right:66px;
margin: 0 0 0 0;
padding: 0 0 0 0;
}
#footer ul{
margin: 0px 0 0 0;
padding: 5px;/* 0 0 0;*/
}
#footer ul li{
list-style-type:circle;
display:inline;
color:white;
margin : 0 35px 0 35px;
font:bold 12px Tahoma;
}
#footer ul li:hover{
color:#FFFF00;
}
#lastpart{
width:1250px;
position: relative;
top: 0px;
margin: 0 0 0 0;
padding: 20px 0 0 0;
background: url("imgbg_body_04.png");
right: 66px;
text-align:center;
font-weight:bold;
color:#660033;
height:56px;
direction: ltr !important;
}
my problem is I want div with id content
go longer or shorter according to biggest div inside it.I tried every possible value for Height
but no one was useful. what should I do?
Thanks in advance.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
这看起来就像一个经典的“CSS断头台”。行上的浮动会阻止
#container
调整其大小。看看这个页面,它解释了一切:
http://css-class.com/articles/探险家/断头台/
简而言之。将此 CSS 添加到您的页面,并将类
clearfix
放在您的#content
上。(使用此解决方案,您不需要带有
clear:both
的额外 div)It seems like a classic "CSS Guillotine". The float on the rows prevents
#container
from adjusting to their size.Have a look at this page which explains everything:
http://css-class.com/articles/explorer/guillotine/
In short. Add this CSS to your page and put the class
clearfix
on your#content
.(With this solution you don't need the additional div with
clear:both
)在关闭
之前,添加一个带有 Clear 类和 css: 的 div,
这样你的 html 就会如下所示:
before you close
<div id="content">
add a div with class clear and the css:so you html would look like this:
如果你想包含浮动,我相信你实际上可以(令人惊讶地)使用溢出属性来做到这一点;
您可以在这里找到另一种更跨浏览器的方法:http://colinaarts.com/articles/float-遏制/
If you want to contain floats, i believe you can actually (surprisingly) do so with the overflow property;
You can find another, more cross browser, method here: http://colinaarts.com/articles/float-containment/
你应该把这个 :
放在每个 div 之间。
(在:
、
和
。)
You should put this :
between each div.
(between :
<div id="content">
,<div id="footer">
and<div id="lastpart">
.)