When to use instead

?

前端 未结 12 1890
故里飘歌
故里飘歌 2020-11-30 20:53

As the question indicates, if I have some text that I want to add in the HTML then when should I use

and when should I use ?<

相关标签:
12条回答
  • 2020-11-30 21:29

    Span is completely non-semantic. It has no meaning, and serves merely as an element for cosmetic effects.

    Paragraphs have semantic meaning - they tell a machine (like a browser or a screen reader) that the content they encapsulate is a block of text, and has the same meaning as a paragraph of text in a book.

    0 讨论(0)
  • 2020-11-30 21:30

    The <p> tag is a paragraph, and as such, it is a block element (as is, for instance, h1 and div), whereas span is an inline element (as, for instance, b and a)

    Block elements by default create some whitespace above and below themselves, and nothing can be aligned next to them, unless you set a float attribute to them.

    Inline elements deal with spans of text inside a paragraph. They typically have no margins, and as such, you cannot, for instance, set a width to it.

    0 讨论(0)
  • 2020-11-30 21:36

    Semantically speaking, a p is a paragraph tag and should be used to format a paragraph of text. A span is an inline formatting change that isn't handled semantically.

    0 讨论(0)
  • 2020-11-30 21:39

    A practical explanation: By default, <p> </p> will add line breaks before and after the enclosed text (so it creates a paragraph). <span> does not do this, that is why it is called inline.

    0 讨论(0)
  • 2020-11-30 21:41

    tag is a block-level element but tag is inline element.Normally we use span tag to style inside block elements.but you don't need to use span tag to inline style.you have to do is; convert block element to inline element using "display: inline"

    0 讨论(0)
  • 2020-11-30 21:43

    You should keep in mind, that HTML is intended to DESCRIBE the content it contains.

    So, if you wish to convey a paragraph, then do so.

    Your comparison isn't exactly right, though. The more direct comparison would be

    When to use a <div> instead of a <p>?

    as both are block level elements.

    A <span> is inline, much like an anchor (<a>), <strong>, emphasis (<em>), etc., so bear in mind that by it's default nature in both html and in natural writing, that a paragraph will cause a break before and after itself, like a <div>.

    Sometimes, when styling things — inline things — a <span> is great to give you something to "hook" the css to, but it is otherwise an empty tag devoid of semantic or stylistic meaning.

    0 讨论(0)
提交回复
热议问题