Three Column DIV layout dynamics; left = fixed, center = fluid, right = fluid

后端 未结 4 761
再見小時候
再見小時候 2020-12-13 07:17

The best solution I found so far was:

http://jsfiddle.net/kizu/UUzE9/

But that wasn\'t quite it. You see, I have three columns; two of which need to avoid be

4条回答
  •  [愿得一人]
    2020-12-13 07:42

    You can do this by using float:left for first column, float:right for the last column and making the center column float:none

    Updated Demo: http://jsfiddle.net/L85rp/3/

    HTML

    Column1
    Column3
    Column2

    CSS

    .col1 {
        background-color: #ddf;
        float: left;
    }
    .col2 {
        background-color: #dfd;
        float: none;
    }
    .col3 {
        background-color: #fdd;
        float: right;
    }
    

    NOTE: It is necessary to place your right column before your center column in HTML (see above, col3 comes before col2 in the HTML) to make sure that when the browser renders the center column, it knows how to render correctly around the existing floating elements.


    Updated CSS

    .col1 {
        background-color: #ddf;
        float: left;
        width: 285px;
        height: 65px;
    }
    .col2 {
        background-color: green;
        float: none;
        height: 65px;
        overflow: hidden;
        display: table-cell; /* turn this off to lock height at 65px */
    }
    .col3 {
        background-color: cyan;
        float: right;
        height: 65px;
    }
    

    Updated demo: http://jsfiddle.net/ew65G/1/

提交回复
热议问题