Two column layout with one having a fixed width in CSS

前端 未结 5 1371
我寻月下人不归
我寻月下人不归 2020-12-20 10:12

I want a nice 2 column layout using CSS float\'s.

Column#1 160 px Column#2 100% (i.e. the rest of the space).

I want to place the Col#2\'s div first, so my l

5条回答
  •  盖世英雄少女心
    2020-12-20 10:12

    Although the question is for years ago, I provide this useful answer for any future reference and similar cases.

    Putting #col1 before #col2 in markup, you may float it to the right, in case you have LTR lauout (if you have an RTL layout then float to the left) and give the other col overflow: hidden.

    Note that the parent ( #content ) should have the overflow: hidden too:

    #content{
      overflow: hidden;
      padding: 20px 0;
      height: 100px;
      background-color: #cdeecd;
    }
    
    #content #col1{
      float: right;
      width: 160px;
      height: 100px;
      background-color: #eecdcd;
    }
    
    #content #col2{
      height: 100px;
      overflow: hidden;
      background-color: #cdcdee;
    }

提交回复
热议问题