为什么没有规则不收缩利润 [英] Why no rule for un-collapsing margins

查看:113
本文介绍了为什么没有规则不收缩利润的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在某些情况下,元素的垂直边距将会折叠。有时,作者不希望这种情况发生,我知道解开边距的唯一方法是:

There are circumstances under which elements' vertical margins will collapse. Sometimes the author doesn't want this to happen, and I understand that the only way to "un-collapse" margins is to:


  • 设置 border sizes> = 1px

  • 设置 padding sized> = 1px

  • Set a border sized >= 1px
  • Set a padding sized >= 1px

这些解决方法对我有意义,但它们只是:解决方法,他们有缺点。我很惊讶,没有某种类型的css3属性像 margin-collapse:none; ,类似于 border-collapse

These workarounds make sense to me, but they are just that: workarounds, and they have drawbacks. I'm surprised that there's not some kind of css3 property like margin-collapse: none;, similar to border-collapse.

设置边框/填充是否是唯一解开边距的方法?

Is it really true that setting a border/padding is the only way to uncollapse margins?

推荐答案

不,有很多其他方法,包括浮动,清除,绝对定位,设置溢出到除 visible ,设置一个 min-height 等等,你可以根据 spec 说。

No, there are numerous other ways, including floating, clearance, absolute positioning, setting overflow to values other than visible, setting a certain min-height, etc, which you can determine based on what the spec says.

但你是对的所有这些都是具有各种副作用和缺点的解决方法,并且在像 margin-collapse 的CSS中没有真正的关闭开关,即使在CSS3框模型模块。一个可能的理由是,利润率崩溃应该是自然发生的,因此,它可以预防的唯一方式是作为副作用,但这只是我的猜测,因为我同意有几种情况下,它是不直观或适当的。

But you're right in that all of these are workarounds with various side effects and disadvantages, and there is no true "off switch" available in CSS like margin-collapse, not even in the CSS3 Box Model module. A possible rationale is that margin collapse is supposed to happen naturally, and therefore the only way it can be prevented is as a side effect, but that's just my guess, as I agree there are several cases where it isn't intuitive or appropriate.

也就是说,如果你感到冒险,你可以在 www-style邮件列表,并看看他们说什么。但我不认为你会有太多的运气。

That said, if you're feeling adventurous you could make a suggestion on the www-style mailing list, and see what they say. I don't think you're going to have much luck, though.

这篇关于为什么没有规则不收缩利润的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆