Equal height CSS columns

喜夏-厌秋 提交于 2020-01-07 16:56:02

问题


Using Equal Height Columns with Cross-Browser CSS example

HTML:

<div id="container1">
  <div id="col1">Column 1<br/>2</div>
    <div id="col2">Column 2</div>
    <div id="col3">Column 3</div>
</div>

CSS:

#container1 {
    float:left;
    width:100%;
}
#col1 {
    float:left;
    width:30%;
    background:red;
}
#col2 {
    float:left;
    width:40%;
    background:yellow;
}
#col3 {
    float:left;
    width:30%;
    background:green;
}

There are more complicated demo pages, but I am looking to use the first example for my purposes. Why isn't the example working?

http://jsfiddle.net/YryJM/2/


回答1:


The simplest way to do equal height columns is with display: table.

#container1 {
    display: table;
    width:100%;
}

#col1, #col2, #col3 {
  display: table-cell;
}
#col1 {
    width:30%;
    background:red;
}
#col2 {
    width:40%;
    background:yellow;
}
#col3 {
    width:30%;
    background:green;
}

http://jsfiddle.net/YryJM/3/




回答2:


maybe this will work? by setting a fixed height of the container div and then setting the col divs to 100%?

#container1 {
float:left;
width:100%;
height:50px;
}
#col1 {
float:left;
width:30%;
background:red;
height:100%;
 }
#col2 {
float:left;
width:40%;
background:yellow;
height:100%;
}
#col3 {
float:left;
width:30%;
background:green;
height:100%;
}

example http://jsfiddle.net/squinny/dps4f/1/

idk if this will help you or not?



来源:https://stackoverflow.com/questions/14220466/equal-height-css-columns

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!