gpt4 book ai didi

css - 冗余 CSS 规则,即 float 和显示 :block

转载 作者:行者123 更新时间:2023-11-27 23:23:35 26 4
gpt4 key购买 nike

我刚刚发现 float 一个元素也会使它成为一个 block ,因此指定一个 float 属性和 display:block 是多余的。

(如果您尝试指定 display:inlinefloat:left 会发生什么?)

是否还有其他需要注意的冗余组合示例? block 和宽度?等等,

是否有可以检查此类内容的工具?

最佳答案

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

是的,如果您指定了 float: left(或 right),display: block 是多余的。

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

display: inline 不会有任何区别,因为设置 float: left 会强制 display: block “无论如何”:

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.

总结一下这个表:float = display: block

但是,您的 float: left; 的具体示例display: inline 在某种程度上很有用 - it fixes an IE6 bug.

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

一些例子:

  • 如果您设置了position: absolute,则强制使用float: none
  • toprightbottomleft 属性不会有任何影响,除非 position 已设置为默认值 static 以外的值。

Is there a tool that can check for such things?

不这么认为。它不是任何时候都需要的东西,所以我不明白为什么有人会编写这样的工具。

关于css - 冗余 CSS 规则,即 float 和显示 :block,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57888167/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com