[英]css floating element increase parent height but sibling with 100% height not working
I have a container with 2 children : one is floating and increasing his parent's height, the second is not floating and fill the rest of the width. 我有一个有2个孩子的容器:一个在漂浮并增加其父母的身高,第二个不在漂浮并填满其余宽度。 I'd like to make the second filling the height also.
我也想使第二个填充高度。
Here is a fiddle of my problem : http://jsfiddle.net/LAesa/ 这是我的问题的小提琴: http : //jsfiddle.net/LAesa/
In this fiddle I'd like to make the red div filling 100% height of his parent. 在这个小提琴中,我要使红色div填充其父代的100%高度。
Here the html : 这里的html:
<div id="container">
<div id="float">
The floating <br/>column
</div>
<div id="fill">
This one fill the rest
</div>
<div class="clearfloat"></div>
</div>
Here the css : 这里的CSS:
#container {
width: 500px;
background-color: yellow;
}
#float {
width: 20%;
float: left;
background-color: green;
}
#fill {
min-height: 100%;
overflow: hidden;
background-color: red;
}
.clearfloat {
clear: both;
}
Thank you very much ! 非常感谢你 !
Provided that you don't need to support older browsers you can also use the flexbox layout. 如果您不需要支持较旧的浏览器,则也可以使用flexbox布局。 http://css-tricks.com/snippets/css/a-guide-to-flexbox/ http://caniuse.com/flexbox
http://css-tricks.com/snippets/css/a-guide-to-flexbox/ http://caniuse.com/flexbox
<div class="flex-container">
<div id="left">
The floating <br/>column
</div>
<div id="right">
This one fill the rest
</div>
</div>
And CSS: 和CSS:
.flex-container {
display: flex;
flex-flow: row no-wrap;
justify-content: space-around;
background: yellow;
width: 500px;
}
#left {
width:20%;
background-color: green;
}
#right {
width:80%;
background-color: red;
}
http://jsfiddle.net/gwwar/KFmVJ/1/ http://jsfiddle.net/gwwar/KFmVJ/1/
Jquery solution, here's a Fiddle jQuery解决方案,这是一个小提琴
$(function() {
var fHgt = $('#float').outerHeight();
$('#fill').css({ height: fHgt });
});
and here's a CSS solution 这是一个CSS解决方案
#container {
display: table;
width: 500px;
background-color: yellow;
}
#float {
display: table-cell;
width: 20%;
background-color: green;
}
#fill {
display: table-cell;
width: 80%;
overflow: hidden;
background-color: red;
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.