我想要实现的是在两个单独的CSS类中设置背景(使用CSS3的多背景会很棒)。我希望尽可能少的标记和普遍性。CSS3跨选择器的多个背景
例子:
CSS
.button {
display: block;
}
.green {
background-color: #87b400;
background: -moz-linear-gradient(top, #a4d400, #739e00);
}
.icon {
background-repeat: no-repeat;
}
.icon.add {
background-image: url('../img/icons/add.png');
}
HTML
<a href="#" class="button green icon add">add item</a>
<input type="submit" name="example" value="add item" class="button green icon add" />
<button type="submit" class="button green icon add">add item</button>
我知道我可以做这样的事情
<a href="#" class="button green"><span class="icon add">add item</span></a>
但我认为有更好的方法,我不能在input
元素内使用它。
我也不想这样做
.button.green.icon.add {
background: -moz-linear-gradient(top, #a4d400, #739e00),
url('../img/icons/add.png');
}
因为有,比方说,5种颜色和11个图标也将是一个恐怖的。
您正在使用哪种浏览器?可以有所作为,因为我认为多个背景支持仍然很不完善。 – 2010-11-15 21:31:23
问题不是关于浏览器支持,没有问题:) – wojtiku 2010-11-15 22:03:29