Using sprites with IMG tag?

后端 未结 6 1461
余生分开走
余生分开走 2020-11-29 23:26

I understand how to use sprites, however, isn\'t a \"src\" attribute required for IMG tags? I could always use a SPAN or other tag and set the background/width/etc but it wo

6条回答
  •  误落风尘
    2020-11-30 00:21

    I could always use a SPAN or other tag and set the background/width/etc but it won't be semantically correct

    Actually there is nothing wrong about using CSS to set the background of a span or div. It would actually be incorrect syntactically to omit the src from an image, as that is the whole point of the tag. There is nothing in the standards saying you have to put text inside a span. Syntactically speaking, modifying the background on an element would be the most "correct" way to do it.

    Here is the ref on img tags over at W3C: http://www.w3.org/TR/html401/struct/objects.html#h-13.2

    And a little extra reading: http://www.w3.org/TR/html4/struct/global.html#h-7.5.3

    These elements define content to be inline (SPAN) or block-level (DIV) but impose no other presentational idioms on the content. Thus, authors may use these elements in conjunction with style sheets, the lang attribute, etc., to tailor HTML to their own needs and tastes.

提交回复
热议问题