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

前端 未结 7 1199
谎友^
谎友^ 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 07:17

    Floating elements can flow "into" block elements, occupying the same line but pushing the contents (not the element itself) over. In this case, left is "inside" right, but there isn't any space left for the text on the right, so it goes underneath. To see what I mean, try setting the width of right to 300px instead of 200px - you should see the blue border "around" left, with the text flowing around it. To "fix" this, I'd suggest giving right a float of left or a display of block-inline.

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