CSS 中未设置的值是什么意思?

What does unset value mean in CSS?

我有一个绝对定位的 megamenu,由于它的一些父元素需要有 position:relative,我必须在直接父元素上使用 position:unset。这适用于 Chrome 和 Firefox,但是 IE11 不支持 unsetinitial

我不能简单地删除所有父元素的相对定位,因为那样会破坏其他东西,但我必须让 megamenu 相对于页面绝对定位(固定位置不起作用)。 unset 是否有可在 IE11 中运行的替代方案?

unset表示

If the cascaded value of a property is the unset keyword, then if it is an inherited property, this is treated as inherit, and if it is not, this is treated as initial. This keyword effectively erases all declared values occurring

在您的情况下,position 不是继承的 属性,因此它将始终考虑 initial

Each property has an initial value, defined in the property’s definition table.

对于 position,它是 static 所以你可以简单地使用 position:static,它的行为与 position:unset

相同

参考:https://drafts.csswg.org/css-cascade-3/


要使其更通用,您必须使用:

  • property:inherit如果是继承财产
  • property:<initial_value>如果不是继承财产。然后你查看属性的定义table找到初始值。

https://developer.mozilla.org/en-US/docs/Web/CSS/position