HTML element which defaults to display:inline-block?

后端 未结 10 2599
北海茫月
北海茫月 2020-12-14 05:33

defaults to block

defaults to inline

Is there one that defaults to inline-

10条回答
  •  天涯浪人
    2020-12-14 05:54

    Is there one that defaults to inline-block?

    Strictly speaking, no there isn't. The W3 HTML specifications do not ever specify default CSS property values for any elements. They do provide a "default style sheet" for HTML 4, but developers are only encouraged to use it - it is not a requirement or any sort of mandate. The HTML 5 specifications indicate "typical default display properties" but, again, those are not required (also keep in mind that HTML 5 is still a working draft anyways).

    So that leaves all default values up to the browser and how the developers actually feel elements should be displayed to a user. No one can guarantee that a specific element will display as inline-block or any other way in someone's browser. You should always explicitly set that if you want it to happen. Don't rely on "defaults."

    If not, what special tag name would be appropriate for me to apply 'inline-block' using CSS? Or should I stick to using a class?

    This is up to you and how you are designing your pages. You should always use elements that are semantically appropriate to the content contained within them. If the element will always be used in a context which will require inline-block display, by all means set it to that in your style sheet. Otherwise, you will have to resort to classes or more specific selectors in order to make your elements display properly.

提交回复
热议问题