Displaying an element similar to p inside a span?

前端 未结 1 479
孤独总比滥情好
孤独总比滥情好 2021-01-05 14:37

I have a span with an inculded p, like this:


    

this is the p

This is not allowed according

1条回答
  •  礼貌的吻别
    2021-01-05 15:05

    p has a meaning.

    If your content matches p’s definition, you should use p. Then you should use a div instead of a span (unless there is no other suitable candidate):

    If your content doesn’t match p’s definition, you shouldn’t use p. Then you could use span instead of p (if there is no other suitable candidate):

    
      
    
    

    span and div don’t have meanings. So you only have to consider where they are placed syntactically (block vs. inline). You can swap them without losing/changing any semantics:

    Note that all this doesn’t have anything to do with how these elements are styled. You can style a block-level element with CSS so that it appears as inline and vice-versa: display:inline; resp. display:block;.

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