Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
281 views
in Technique[技术] by (71.8m points)

html - Div display:initial not working as intended in ie10 and chrome 29

I want to display a div with the following restrictions:

  • automatically hide under 1024px width
  • can be toggle by button under 1024px width, but if I click somwhere (not inside the div) the activeDiv class should be removed

I have a dummy example at codepen

So the following problems occured:

  • In IE10 the toggle button just not work (not hide/show the div) I check with the developer tools, but no sign of the display: initial
  • In Chrome 29 the div appeard next the button not under it. (Firefox is the same)
    I know that the default display for div is block, but this css is not only for div tags that's why I try to use initial.
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

initial does not mean "the default value of a given property for a given element". It means "the default value of a given property as defined by the spec". The initial value of display is inline, not block, as stated here. This is regardless of what sort of element you apply it to. And as already mentioned, IE does not support the initial keyword.

If you want an element to be displayed as a block, use display: block. If you want it to be displayed inline, use display: inline. If you want it to use whichever is the browser default for it, do not set the display property at all.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...