What happens with display:initial on non CSS3 browsers?

纵然是瞬间 提交于 2019-12-10 17:36:19

问题


I need to know what value/ css would be set when I use display: initial on non CSS3 compliant browsers ?

I'm hiding the class using display:none & need to show back, for which I intend to use display: initial (I dont want to use display:block if previously it was display:inline) but the hidden element must be shown on all browsers.


回答1:


What happens by CSS 2.1 rules on error handling as well as in practice is that the declaration display: initial is ignored, without affecting the rest of the style sheet. The display property thus gets its value from other rules. In the absence of any setting on it in any style sheet (including browser default style sheet), the initial value inline is used.

The “fallback” code in the edit of your question means that the value of display would be inline in browsers that support the value inline, and block in other browsers. This does not sound safe.

The value initial does not mean “the previous value set in a style sheet” or anything like that, as the question seems to postulate. Instead, it means the value that is designated as the property’s initial value in CSS specifications. For display, this is inline.




回答2:


Ok, I found that providing a fallback would be a safer option. So I use like below:

{
display: block;// just as fallback
display: initial;
}



回答3:


there is "run-in" value for display property explained in W3C Schools page

EDIT: run-in value is supported by Internet Explorer, and interpret the element whether it is block-level or inline-level.

I made an example jsFiddle Example .



来源:https://stackoverflow.com/questions/15995816/what-happens-with-displayinitial-on-non-css3-browsers

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