具有动态高度的CSS和DIV
我有一个这样的网页结构:具有动态高度的CSS和DIV,css,html,dynamic,height,Css,Html,Dynamic,Height,我有一个这样的网页结构: <div class="total"> <div class="menu"> </div> <div class="content"> </div> </div> 问题是我无法获得我真正想要的:边框都在顶部,就像一个水平行,我的div没有显示不同的背景色 如何使总div的高度动态化 编辑:链接到“.total”元素已完全折叠,因为它的所有子元素都处于浮动状态。您所需
<div class="total">
<div class="menu">
</div>
<div class="content">
</div>
</div>
问题是我无法获得我真正想要的:边框都在顶部,就像一个水平行,我的div没有显示不同的背景色
如何使总div的高度动态化
编辑:链接到“.total”元素已完全折叠,因为它的所有子元素都处于浮动状态。您所需要做的就是添加一个clearfix
清除浮动的其他方法可以在这里找到:由于其所有子元素都是浮动的,.total元素已完全折叠。您所需要做的就是添加一个clearfix
清除浮动的其他方法可在此处找到:您可以使用clearfix修复此问题: 将其添加到css中,并将cf类添加到div.content中
/**
* For modern browsers
* 1. The space content is one way to avoid an Opera bug when the
* contenteditable attribute is included anywhere else in the document.
* Otherwise it causes space to appear at the top and bottom of elements
* that are clearfixed.
* 2. The use of `table` rather than `block` is only necessary if using
* `:before` to contain the top-margins of child elements.
*/
.cf:before,
.cf:after {
content: " "; /* 1 */
display: table; /* 2 */
}
.cf:after {
clear: both;
}
/**
* For IE 6/7 only
* Include this rule to trigger hasLayout and contain floats.
*/
.cf {
*zoom: 1;
}
测试:您可以使用clearfix修复此问题: 将其添加到css中,并将cf类添加到div.content中
/**
* For modern browsers
* 1. The space content is one way to avoid an Opera bug when the
* contenteditable attribute is included anywhere else in the document.
* Otherwise it causes space to appear at the top and bottom of elements
* that are clearfixed.
* 2. The use of `table` rather than `block` is only necessary if using
* `:before` to contain the top-margins of child elements.
*/
.cf:before,
.cf:after {
content: " "; /* 1 */
display: table; /* 2 */
}
.cf:after {
clear: both;
}
/**
* For IE 6/7 only
* Include this rule to trigger hasLayout and contain floats.
*/
.cf {
*zoom: 1;
}
测试:他的意思是发布一个在JSFIDLE上不起作用的示例代码,以便对其进行观察和测试以发现问题。比如:这一次是为你做的,所以你知道下一次的问题肯定来自div.menu或div.content的CSS/HTML,我们可以看到CSS吗?他的意思是发布一个在JSFIDLE上不起作用的示例代码,以便可以观察和测试以发现问题。比如:这次是为你做的,所以你知道下一次的问题肯定来自div.menu或div.content的CSS/HTML,我们能看到CSS吗?
/**
* For modern browsers
* 1. The space content is one way to avoid an Opera bug when the
* contenteditable attribute is included anywhere else in the document.
* Otherwise it causes space to appear at the top and bottom of elements
* that are clearfixed.
* 2. The use of `table` rather than `block` is only necessary if using
* `:before` to contain the top-margins of child elements.
*/
.cf:before,
.cf:after {
content: " "; /* 1 */
display: table; /* 2 */
}
.cf:after {
clear: both;
}
/**
* For IE 6/7 only
* Include this rule to trigger hasLayout and contain floats.
*/
.cf {
*zoom: 1;
}