简体   繁体   English

CSS:具有半流体中心的三列布局

[英]CSS: Three-column layout with a semi-fluid center

I'm attempting to create a basic 3-column layout. 我正在尝试创建基本的3列布局。 Essentially the center column should be fluid in that it should expand to consume any space not used by the left and right columns. 本质上,中柱应该是流动的,因为它应该膨胀以消耗左柱和右柱未使用的任何空间。 However, it also needs to have a fixed min-width of approximately 378 pixels. 但是,它还需要具有约378个像素的固定min-width

There are a number of options for creating a 3-column layout with a completely fluid center column, with or without using floats. 有许多用于与一个完全流体中心柱创建3列布局,选项使用浮动。 However, the problem with every prepackaged solution I've come across so far (as well as the ones I've tried myself) is that as the page width is decreased the right column will come over the top of the center column once the page gets too narrow. 但是,到目前为止,我遇到的每个预打包解决方案(以及我自己尝试过的解决方案)的问题是,随着页面宽度的减小,一旦页面缩小,右列将位于中间列的顶部变得太狭窄。

I'd like to prevent this, if possible. 如果可能,我想防止这种情况。 Ideally once the min-width is hit the right column should stay where it is, and the page should become horizontally scrollable. 理想情况是,一旦达到min-width则右列应保持在原位置,并且页面应可水平滚动。 So the goal is: 因此,目标是:

  1. A 3-column layout with a fluid center column and fixed-width left and right columns. 3列布局,带有流体中心柱和固定宽度的左右柱。
  2. A center column with a fixed minimum width to prevent it from becoming too small. 具有固定最小宽度的中心列,以防止它变得太小。
  3. A right-column that respects the minimum width and does not trample, float over, or wrap below the center column when the window becomes too small. 当窗口变得太小时,一个遵循最小宽度并且不践踏,不漂浮或不包裹在中心列下方的右列。

A pure-CSS solution is preferred, but if there's a simple way to do this using some clever JavaScript I've got no objection to that approach either. 首选纯CSS解决方案,但是如果有使用一些聪明的JavaScript的简单方法,我也不反对这种方法。

For this you can use display:table property. 为此,您可以使用display:table属性。 Write like this: 这样写:

#wrapper{
    display:table;
    width:100%;
    height:100%;
}
#wrapper > div{
    display:table-cell;
    height:100%;
}

#left {
    width:50px;
    min-width:50px;
    background-color:pink;
}

#center {
    background-color:green;
    min-width:200px;
}

#right {
    width:50px;
    min-width:50px;
    background-color:red;
}

body, html{
    width:100%;
    height:100%;

}

Check this http://jsfiddle.net/ykAPM/137/ 检查此http://jsfiddle.net/ykAPM/137/

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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