开发者

What html tag best to use with sprites

开发者 https://www.devze.com 2023-01-20 14:51 出处:网络
I would like to use sprites to display my icons. I created image and CSS, now I need to add class to my html element. What is the best HTML element for that?

I would like to use sprites to display my icons. I created image and CSS, now I need to add class to my html element. What is the best HTML element for that?

<div> works fine, but of course it spans a开发者_Go百科cross entire space and wraps. works only if I put something in it. Here's my CSS

.sprite {
    background:url('/i/sprites.png');
    background-repeat:no-repeat
}
.ico2{
    background-position:0 -104px;
    width:16px;
    height:16px
}


My opinion is that it doesn't matter. Whatever tags are suitable for the rest of your content.

  • <ul><li></li></ul> structures are very flexible for layout.
  • <div> and <span>of course.
  • I often find myself using sprites for buttons in links.

You'll probably want to use display: block or display: inline-block for most of the elements where you put your sprites, and remember that you can set that for all elements.


It depends on context. Try to choose the element which best represents the semantics of the data, not on how it will be displayed; that's what CSS is for.

Are you displaying a list of icons? Use a <ul> and put your sprites in its <li> elements.


You could use <span> tags and set it's display to inline-block with defined height and width.

0

精彩评论

暂无评论...
验证码 换一张
取 消