[英]3 columns with third column having fluid width, fixed position
I would like to do this simple layout: 我想做这个简单的布局:
width = 200px
width = 200px
width = 400px
width = 400px
This is the sample I have (but with col3's width as 100px ). 这是我的示例(但col3的宽度为100px )。 So the question is how to fix css of
col3
to make it fluid but still reserve position:fixed
? 所以问题是如何固定
col3
css以使其流畅但仍保留position:fixed
?
http://jsfiddle.net/Endt7/1/ http://jsfiddle.net/Endt7/1/
My last alternative is to use jQuery. 我最后的选择是使用jQuery。 But I don't want to touch it unless really necessary for layout.
但是除非布局真正必要,否则我不想触摸它。
Thanks. 谢谢。
For absolute/fixed positioned elements, width is a function of left and right. 对于绝对/固定位置的元素,宽度是左右的函数。 So, set the
left: 600px; right: 0;
因此,将
left: 600px; right: 0;
设置为left: 600px; right: 0;
left: 600px; right: 0;
on the third column and browser will determine the width. 在第三列上,浏览器将确定宽度。 That is it.
这就对了。 Here is the revised CSS, with few changes for consistency:
这是经过修订的CSS,为保持一致而进行了一些更改:
.col1 {
position: fixed;
top: 0;
bottom: 0;
left: 0;
width: 200px;
background: red;
}
.col2 {
margin-left: 200px;
width: 400px;
height: 100%;
background: green;
}
.col3 {
position: fixed;
top: 0;
bottom: 0;
left: 600px;
right: 0;
background: blue;
}
Can do it using float:left
or absolute position for the left and middle columns and set margin-left
equal to their combined widths. 可以使用
float:left
或left和middle列的绝对位置,并设置margin-left
等于它们的组合宽度来做到这一点。
.col1 {
background: red;
float:left;
width: 200px;
height:100%
}
.col2 {
background: green;
float:left;
width: 400px;
height:100%
}
.col3 {
background: blue;
margin-left:600px;
}
DEMO: http://jsfiddle.net/Endt7/3/ 演示: http : //jsfiddle.net/Endt7/3/
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.