Difference between DIV as-is and a SPAN with display:block

前端 未结 4 1329
夕颜
夕颜 2020-12-09 08:06

Is

different from in any way?

They render just fine the same. Any semantic difference b

4条回答
  •  醉梦人生
    2020-12-09 08:38

    A

    is a block level element that has no specific semantics of its own, beyond defining a discrete block of content. A is an inline element that has no specific semantics of its own, beyond defining a discrete segment of inline content.

    You can use CSS to make a span display as a block, but there is absolutely no reason to do so EDIT: other than for purely visual effects, as Gabriel demonstrates; what I mean is that you shouldn't use CSS to try to coerce a span into having block-level significance in terms of document structure. Furthermore, if you do, your content will probably appear meaningless to a user without CSS, such as a blind user, or a search engine.

    If it's a block, use a div. If it's part of inline content, use a span. Remember, CSS is about presentation alone; your markup still needs to be structured in a logical manner if your content is to be usable.

    See http://www.w3.org/TR/html401/struct/global.html#edef-DIV for the details.

提交回复
热议问题