CSS Floating inline elements (960 GS)

て烟熏妆下的殇ゞ 提交于 2019-12-01 21:03:17
thirtydot

An element with float: left is forced to have a computed display value of block.

For more information on that, see: jQuery in Chrome returns "block" instead of "inline"

The purpose of also adding display: inline is to fix an IE6 bug, the "double margin bug":

http://www.positioniseverything.net/explorer/doubled-margin.html

A coder innocently places a left float into a container box, and uses a left margin on the float to push it away from the left side of the container. Seems pretty simple, right? Well it is until it's viewed in IE6. In that browser the left float margin has mysteriously been doubled in length!

It's a free fix with no downsides (even in IE6):

That means that {display: inline;} on a float should be no different than using {display: block;} (or no display value at all), and indeed all browsers follow this specification, including IE. But, this does somehow trigger IE to stop doubling the float's margin. Thus, this fix can be applied straight, without any fussy hiding methods.

In fact, you could just apply the Inline Fix to all floats if you like, since there are no known side-effects. That way the bug can never gain traction regardless of any margins you might or might not use.

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!