Why `float:left` doesn't work with a fixed width?

前端 未结 7 1300
谎友^
谎友^ 2021-01-02 06:39

I have two divs on a webpage and I would like both of them to have a fixed width and would like the first div to be floated to the left of the second div.

This sound

7条回答
  •  [愿得一人]
    2021-01-02 06:53

    Float both divs left.

    Apply a positive left margin of width(div.right), in your case 200px.

    Apply a negative left margin of width(div.left) + width(div.right), in your case, 200px + 200px = 400px.

    div.left { float: left; width: 200px; margin-left: 200px; }
    div.right { float: left; width: 200px; margin-left: -400px; }
    

提交回复
热议问题