简体   繁体   English

3列,第三列具有流体宽度,固定位置

[英]3 columns with third column having fluid width, fixed position

I would like to do this simple layout: 我想做这个简单的布局:

  1. 3 columns with left and right position:fixed because when scroll down, left and right supposed to stay still 3列,左右位置:固定,因为向下滚动时左右应保持静止
  2. We know left column width = 200px 我们知道左列width = 200px
  3. We know middle column width = 400px 我们知道中间列的width = 400px
  4. We DON'T know right column width and it should be fluid (ie fill in rest of the screen width OR zero) 我们不知道正确的列宽,它应该是可变的 (即填写屏幕的其余宽度或为零)

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;
}

Demo here 在这里演示

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM