Redundant CSS rules ie float & display:block

前端 未结 2 1224
一个人的身影
一个人的身影 2020-12-01 11:29

I just found out that floating an element will also make it a block, therefore specifying a float property and display:block is redundant.

(What wo

相关标签:
2条回答
  • 2020-12-01 12:01

    I just found out that floating an element will also make it a block, therefore specifying a float property and display:block is redundant.

    Yes, display: block is redundant if you've specified float: left (or right).

    (What would happen if you tried to specify display:inline and float:left? )

    display: inline will not make any difference, because setting float: left forces display: block "no matter what":

    http://www.w3.org/TR/CSS2/visuren.html#dis-pos-flo

    Otherwise, if 'float' has a value other than 'none', the box is floated and 'display' is set according to the table below.

    To summarize said table: float = display: block.

    However, your specific example of float: left; display: inline is useful in one way - it fixes an IE6 bug.

    Are there any other examples of redundant combinations to watch out for? block & width ? etc,

    Some examples:

    • If you set position: absolute, then float: none is forced.
    • The top, right, bottom, left properties will not have any effect unless position has been set to a value other than the default of static.

    Is there a tool that can check for such things?

    I don't think so. It's not something that is ever needed, so I can't see why anybody would have written such a tool.

    0 讨论(0)
  • 2020-12-01 12:03

    From my experience IE6 has problems with float:left. For compatibility, display:inline is added with floating statements.

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