操纵元素背景

时间:2012-11-27 10:16:03

标签: html css image css3

当您在div中有图像时,请说:

<div class="reflection">
<img src="example" alt="" />
</div>

您只能使用.reflection img { // do stuff here }

来引用特定元素

我只想引用一个background:的CSS元素,因为我正在使用模板,所有图像都是使用CSS显示而不是HTML,如下所示:

.exampleClass { background: url("path here") no-repeat scroll 0 0 transparent; }

如何在CSS中引用该类的背景?

3 个答案:

答案 0 :(得分:0)

只需创建自己的类..

<强> HTML

<div class="reflection background">
<img src="example" alt="" />

<强> CSS

.background { background: url("path here") no-repeat scroll 0 0 transparent; }

可以将.background类赋予您想要拥有背景的任何元素。

答案 1 :(得分:0)

只需使用.reflection {}并操纵背景。这是一个CSS属性(background),因此您可以在最初定义之后对其进行更改。

答案 2 :(得分:0)

只需添加2个课程。即:

<div class="reflection defaultBackground">
    <img src="example" alt="" />
</div>

然后你可以在.reflection img和.defaultBackground img上添加样式。

相关问题