CSS Position Unset in IE11

为君一笑 提交于 2019-12-23 22:52:51

问题


I have a megamenu that is absolutely positioned, and as some of its parent elements need to have position:relative, I have to use position:unset on the direct parent. This works in Chrome and Firefox, however IE11 does not support unset or initial.

I can't simply remove the relative positioning from all of the parent elements as that will break other things, but I have to have the megamenu absolutely positioned relative to the page (fixed position does not work). Is there an alternative to unset that will work in IE11?


回答1:


unset means

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

In your case, position is not an inherited property so it will always consider initial

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

For position, it's static So you can simply use position:static and it will behave the same as position:unset


Reference: https://drafts.csswg.org/css-cascade-3/


To make this more generic you have to either use:

  • property:inherit if it's an inhertied propety
  • property:<initial_value> if it's not an inhertied propety. Then you look at the property’s definition table to find the initial value.

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



来源:https://stackoverflow.com/questions/56859256/css-position-unset-in-ie11

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