centering a div between one that's floated right and one that's floated left

后端 未结 7 1178
天命终不由人
天命终不由人 2020-12-02 14:04

I have a page in which a header consists of three divs - one that\'s floated to the left, one that\'s floated to the right, and one that\'s in between them. I\'d like for th

相关标签:
7条回答
  • 2020-12-02 14:50

    Try this (make sure to use better class names):

    .left {
     float:left;
     width:200px;
    }
    .right{
     float:right;
     width:200px;
    }
    .center {
     overflow:hidden;
     zoom:1;
    }
    

    The center div will fit between the two floats.
    If you want to create a gutter between that centered div and the two floats, then use margin on the floats, not on the center div.

    Because of "zoom", the CSS will not validate, but that layout will work in IE 5.5 and 6.

    Note that source order is important here: the two floats must come first, then your "centered" div.

    0 讨论(0)
提交回复
热议问题