【发布时间】:2012-09-15 11:32:50
【问题描述】:
我有一个用于article 和section HTML5 标记的类。
在家里:
<article class="exit">
<a href="exit.php">
<figure class="box">
<img src="assets/img/projects/exit-m.jpg" alt="">
<figcaption>…</figcaption>
</figure>
</a>
</article>
在项目页面上:
<section class="page project exit">
<div class="corner nw intro">
<figure class="box">
<img src="assets/img/projects/exit.jpg" alt="">
<figcaption>…</figcaption>
</figure>
</div>
…
exit 类的每个元素内部都有一个figure HTML5 元素。有了 Less,我可以使用这段代码来做我想做的事。
article.exit{width:260px; height:200px; top:315px; left:505px;
figure{background-color:@exit-bg;}
.box:hover{.perspective-box(se, 10, @exit-shadow);}
}
section.exit{
.box:hover{.perspective-box(nw, 10, @exit-shadow);}
.intro figcaption:hover{background:@exit-hover;}
}
但我必须指定它是article 还是section!我有很多这样的课程,这有点烦人……
有没有解决方案来做这样的事情?会很酷……
.exit{
&article{
width:260px; height:200px; top:315px; left:505px;
figure{background-color:@exit-bg;}
.box:hover{.perspective-box(se, 10, @exit-shadow);}
}
§ion{
.box:hover{.perspective-box(nw, 10, @exit-shadow);}
.intro figcaption:hover{background:@exit-hover;}
}
}
【问题讨论】:
-
CSS 不支持嵌套。如果这样做会非常方便,但 W3C 并不是要让人们的生活变得轻松。
-
是的,但我使用 LESS CSS,它接受这种嵌套……也许不是我搜索的内容,但它有效。 lesscss.org/#-nested-rules