Difference between div and span

后端 未结 3 1609
太阳男子
太阳男子 2020-12-17 05:01

What is the difference between div with the property display:inline-block and span with display:inline-block?

3条回答
  •  野趣味
    野趣味 (楼主)
    2020-12-17 05:33

    Just wanted to add some historical context to how there came to be span vs div

    History of span:

    On July 3, 1995, Benjamin C. W. Sittler proposes a generic text container tag for applying styles to certain blocks of text. The rendering is neutral except if used in conjunction of a stylesheet. There is a debate around versus about readability, meaning. Bert Bos is mentioning the extensibility nature of the element through the class attribute (with values such as city, person, date, etc.). Paul Prescod is worried that both elements will be abused. He is opposed to text mentioning that "any new element should be on an old one" and adding "If we create a tag with no semantics it can be used anywhere without ever being wrong. We must force authors to properly tag the semantics of their document. We must force editor vendors to make that choice explicit in their interfaces."

    - Source (w3 wiki)

    From the RFC draft that introduces span:

    First, a generic container is needed to carry the LANG and BIDI attributes in cases where no other element is appropriate; the SPAN element is introduced for that purpose.

    - Source (IETF Draft)

    History of div:

    CENTER was introduced by Netscape before they added support for the HTML 3.0 DIV element. It is retained in HTML 3.2 on account of its widespread deployment.

    HTML 3.2 Spec

    In a nutshell, both elements arose out of a need for a more generic container that didn't have attached semantics. Span was proposed as a more generic replacement for a element to style text. Div was proposed as a generic way to divide pages and had the added benefit of replacing the

    tag for center-aligning content. Div has always been a block element because of its history as a page divider. Span has always been an inline element because its original purpose was text styling and today div and span have both arrived at being generic elements with default block and inline display properties respectively.

提交回复
热议问题