Can we place `` >`

后端 未结 5 1072
时光说笑
时光说笑 2020-12-05 04:04

Can we place inside

according to web standards? like this

Demo text

相关标签:
5条回答
  • 2020-12-05 04:27

    To summarize the other answers, it is W3C valid to use an <img> inside an <h1>.

    Though to be completly valid you should add an alt attribute to your image, because it's mandatory. This attribute doesn't need to contain text. It's better letting it empty than repeating what is already written in the h1 tag.

    In your case if the image is purely decorative it should be:

    <h1>Demo text <img src="anyimage.jpg" alt=""/></h1>
    

    More info on text alternatives for decorative images: https://www.w3.org/WAI/tutorials/images/decorative/

    If the image has a particular meaning or contains a text different than the one in the h1, then use an appropriate alternative.

    0 讨论(0)
  • 2020-12-05 04:33

    Yes, this is allowed. But don’t forget to set the alt attribute on the img!

    0 讨论(0)
  • 2020-12-05 04:44

    Yes and no.

    You can place an image inside an h1 element, but not quite like that … the alt attribute is mandatory.

    0 讨论(0)
  • 2020-12-05 04:46

    Yes, you can - the DTD says:

    <!ELEMENT h1  %Inline;>
    <!ENTITY % Inline "(#PCDATA | %inline; | %misc.inline;)*">
    <!ENTITY % inline "a | %special; | %fontstyle; | %phrase; | %inline.forms;">
    <!ENTITY % special "%special.pre; | object | img ">
    

    That basically means h1 can contain %Inline, which is made of various things, including img

    0 讨论(0)
  • 2020-12-05 04:47

    Look who is using it: http://www.w3.org/

    <h1 class="logo"><a tabindex="2" accesskey="1" href="/"><img src="/2008/site/images/logo-w3c-mobile-lg" width="90" height="53" alt="W3C" /></a> <span class="alt-logo">W3C</span></h1>
    
    0 讨论(0)
提交回复
热议问题