Can we place `` >`

2019-01-13 19:39发布

Can we place <img> inside <h1> according to web standards? like this

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

4条回答
我欲成王,谁敢阻挡
2楼-- · 2019-01-13 20:14

Yes and no.

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

查看更多
ら.Afraid
3楼-- · 2019-01-13 20:16

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>
查看更多
爱情/是我丢掉的垃圾
4楼-- · 2019-01-13 20:24

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

查看更多
淡お忘
5楼-- · 2019-01-13 20:27

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

查看更多
登录 后发表回答