Ada*_*ite 7 css height positioning css-float
我正在努力让div完全扩展到它的容器高度.
标记:
<div class="container">
<div class="innerOne inner"></div>
<div class="innerTwo inner"></div>
</div>
Run Code Online (Sandbox Code Playgroud)
在不同的视口中.innerTwo,内容比我们的内容高,.innerOne但我希望它的背景与.innerTwos的大小相同
样式:
.container {
width: 100%;
height: auto;
background-color: yellow;
/* clearfix */
*zoom: 1;
&:before,
&:after {
display: table;
content: "";
line-height: 0;
}
&:after {
clear: both;
}
}
.inner {
float: left;
width: 50%;
height: 100%;
background-color: red;
}
Run Code Online (Sandbox Code Playgroud)
但高度不会匹配.我知道可以通过给容器设置一个高度来完成它,但我不想这样做,因为它是一个响应式站点.这可能吗?我宁愿不使用JS.
san*_*eep 14
您可以使用display:table-cell属性.像这样写:
.container{
width:100%;
border:1px solid red;
display:table;
}
.inner{
display:table-cell;
background:green;
width:50%;
}
.innerTwo{
background:blue
}
Run Code Online (Sandbox Code Playgroud)
检查这个http://jsfiddle.net/XXHTC/
本文讨论响应式媒体中的宽高比和大小问题。这可能不是您特定问题的答案,但讨论百分比填充的使用的部分有时对我有帮助。http://css-tricks.com/rundown-of-handling-flexible-media/