如何将高度设置为100%的元素,其位置固定取决于其包装高度

时间:2015-08-06 08:53:35

标签: height fixed sidebar

这是小提琴Link

.homeFirstSection {
float: left;
width: 100%;
height: 500px;
position: relative;
}
.home_left_bar {
float: left;
background: #f67777;
width: 4%;
height: 100%;
z-index: 5;
position: fixed;
 }

如何将固定部分的高度设置为其包裹的高度?

1 个答案:

答案 0 :(得分:0)

找到一个非常简单的解决方案,只设置css高度为inherit.Here是Fiddle和代码

.homeFirstSection {
float: left;
width: 100%;
height: 200px;
position: relative;
}
.home_left_bar {
float: left;
background: #f67777;
width: 4%;
height: inherit;
z-index: 5;
position: fixed;
}