精灵没有显示

时间:2014-04-01 21:00:57

标签: html css css-sprites sprite

我想将精灵用于一组我希望在网站上显示的图标。当使用下面的代码时,只有sprite没有出现,但是我使用的生成器声明这是用于显示sprite图像的正确css格式。

<html>
<style>
    #sprite{
    background: url(sprites.png) no-repeat top left;
}

.sprite-clock{ background-position: 0 0; width: 40px; height: 40px; display: block;  } 
.sprite-paintcan{ background-position: 0 -90px; width: 40px; height: 40px; display: block; } 
.sprite-swatches{ background-position: 0 -180px; width: 40px; height: 40px; display: block;  } 
.sprite-trophy{ background-position: 0 -270px; width: 40px; height: 40px; display: block;  }
</style>

<body>

<div id="sprite">

<div class="sprite-clock"><h3>Management</h3><p>Paullum deliquit, ponderibus modulisque suis ratio utitur.</p></div>

    <div class="sprite-paintcan">
    <h3>Professional</h3>
    <p>Paullum deliquit, ponderibus modulisque suis ratio utitur.</p>
    </div>

    <div class="sprite-swatches">
    <h3>Creativity</h3>
    <p>Paullum deliquit, ponderibus modulisque suis ratio utitur.</p>
    </div>

    <div class="sprite-trophy">
    <h3>Innovation</h3>
    <p>Paullum deliquit, ponderibus modulisque suis ratio utitur.</p>
    </div>
</div><!-- sprite-->

</body>
</html>

2 个答案:

答案 0 :(得分:1)

background属性不会继承到元素子元素。所以把它写到每个精灵类

sprite-clock{
    background: url(sprites.png) no-repeat top left;
    background-position: ....

答案 1 :(得分:0)

尝试为所有类添加background-url