Is header in legend valid?

Caption

前端 未结 7 1190
萌比男神i
萌比男神i 2021-01-17 21:20

I use this in visual studio but the compiler claimed that h1 cannot be nested in legend element, but browser can render it anyway so i am confused

7条回答
  •  一向
    一向 (楼主)
    2021-01-17 21:51

    The legend element of the fieldset is not designed to allow child elements unless they are considered "phrasing content". While most browsers will not complain (thus making it valid in pratice) you would probably be better off using a style to set the look/feel of your legend element as that is what css is for, elements should be used for logically grouping/identifing content not styling it.

    Legend: http://www.w3.org/TR/html5/forms.html#the-legend-element

    Phrasing Content: http://www.w3.org/TR/html5/content-models.html#phrasing-content

提交回复
热议问题