What happens to the remaining 1px when a div with an odd width is split 50%/50%?

前端 未结 2 1844
一生所求
一生所求 2021-01-12 00:50

Let\'s say I wanted to make a background for div#wrapper so that half is blue and half is red using two divs with width:50%, like so:

HTML:

2条回答
  •  孤独总比滥情好
    2021-01-12 01:17

    One possible solution is not set a width to the second DIV (#rightSide) and set float: left; only on the left DIV. Since these are block elements, they will always expand to the full available width if none was set.

    In the example, the wrapper width is 3px, the left container has a width of 1-2px (depending on the browser) and the right container will require the leftover horizontal space inside the wrapper:

    http://jsfiddle.net/dq323/1/

提交回复
热议问题