html - 将 CSS sprites 用于列表 (<li>) 背景图像

标签 html css css-sprites

是否可以将 CSS sprites 用于列表背景图像?通常,我会像这样使用 CSS 渲染 Sprite :

.sprite { background: url(sprite.png) no-repeat top left;}
.sprite-checkmark { background-position: 0 -24px; width: 24px; height: 23px; } 
.sprite-comment { background-position: 0 -48px; width: 14px; height: 14px; }

<div class="sprite sprite-checkmark"></div>

是否可以为

  • 元素的元素符号使用 sprite?有称为 list-style-image 和 list-style-position 的 CSS 属性,但我不确定如何在不存在 list-style-image-width 和 list-style-image-height 等属性的情况下使其工作

    谢谢。

  • 最佳答案

    你也可以使用

    li:before {
        background:url(..) no-repeat -##px -##px;
        width:##px;
        height:##px;
        display:block;
        position:absolute;
        content: " ";
        top:##px;
        left:##px;
    }
    

    然后将一个额外的元素添加到 DOM 中并为其提供背景图像。

    关于html - 将 CSS sprites 用于列表 (<li>) 背景图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2381789/

    相关文章:

    html - 以内联方式放置对象(显示)

    jquery - 将 JQuery 与图像 Sprite 一起使用

    html - CSS 未知属性 "transform"

    css - 提交按钮在移动网站上呈现奇怪的效果

    html - 空间出现在 firefox 上,但不是 chrome?

    css - Sprite 图像的嵌套CSS类

    html - 在 sprite 中使用 Logo 标签是好是坏?

    javascript - css 响应高度或 div 的比例

    javascript - 如何让网页只显示一次?

    html - 将图像显示为 src="data : image/jpg;base64, ... 好吗?