开发者

gap between two 50% width divs

I have a container <div> with a width of 181px.

I have two child <div> elements in my container div each with a width of 50%.

My problem is that each of my child <div> elements has a width of only 90px, 开发者_运维技巧resulting in a 1px gap between the two.

Any suggestions for removing the gap?


Set the width of one div as 50% and the other can use the standard block behavior of consuming the rest of the width:

<div style="width: 181px;">
    <div style="width: 50%; float: left;"></div>
    <div></div>
</div>


style them as floats?

<div style="width:181px;border:1px solid;height:100px;">
    <div style="width:50%;background:#F00;height:100%;float:left;"></div>
    <div style="width:50%;background:#00F;height:100%;float:left;"></div>
</div>


You can't split 181 pixels in half. A pixel is a pixel on a display and you can't get 2 50% elements to split the 181px in half. One needs to be 90px and one needs to be 91px.

If you float them both to the same direction, either left or right, the gab between them would go away but you would probably still have a 1px gap on the other side--if that matters. If you have borders on these elements and you're using floats then you'll have a whole new set of cross-browser issues. Make sure you do some cross-browser testing.


Well the value get rounded to integer.

Here is a very good thread which goes into much more detail.

Are the decimal places in a CSS width respected?

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜