例如,如果我有以下HTML:
- <div class="someDiv"></div>
和这个CSS:
- .opacity {
- filter:alpha(opacity=60);
- -moz-opacity:0.6;
- -khtml-opacity: 0.6;
- opacity: 0.6;
- }
- .radius {
- border-top-left-radius: 15px;
- border-top-right-radius: 5px;
- -moz-border-radius-topleft: 10px;
- -moz-border-radius-topright: 10px;
- }
- .someDiv {
- background: #000; height: 50px; width: 200px;
- /*** How can I reference the opacity and radius classes here
- so this div has those generic rules applied to it as well ***/
- }
解决方法
不,您不能从另一个引用一个规则集。
但是,您可以在样式表中的多个规则集上重复使用选择器,并在单个规则集(由separating them with a comma)上使用多个选择器。
- .opacity,.someDiv {
- filter:alpha(opacity=60);
- -moz-opacity:0.6;
- -khtml-opacity: 0.6;
- opacity: 0.6;
- }
- .radius,.someDiv {
- border-top-left-radius: 15px;
- border-top-right-radius: 5px;
- -moz-border-radius-topleft: 10px;
- -moz-border-radius-topright: 10px;
- }
您还可以将多个类应用于单个HTML元素(类属性采用空格分隔列表)。
- <div class="opacity radius">
它可能会帮助,如果你使用类名称描述为什么元素应该样式,而不是如何应该样式。保留样式表中的方式。