Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

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/

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
142 views
Welcome To Ask or Share your Answers For Others

1 Answer

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/


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
...