我想知道有没有什么办法让CSS的下面的例子工作,因为我打算?有没有办法指定第一个元素* type *?
<!DOCTYPE html>
<html>
<head>
<style type="text/css">
.col p:first-child {
background:yellow;
}
</style>
</head>
<body>
<div class="col">
<h1>Woot</h1>
<p>I am a super nun. I am a super nun.</p>
<p>I am a super nun. I am a super nun.</p>
</div>
</body>
</html>
基本上我需要一个元素的第一<p>
被称呼一定的方式......但first-child
如果它的第二个孩子(废话),即使我试图说不行:“第一父亲中的<p>
元素(即.col p:first-child
)“。
是否可以在CSS中选择不是第一个孩子,而是特定类型的第一个孩子?
为什么不使用一般的兄弟选择器作为“div.col〜p” – Jawad 2011-05-26 17:37:36
@ JAA149:因为那会选择多个'p'。 – BoltClock 2011-05-26 17:38:56
比我们可以使用相邻的兄弟选择器作为“h1 + p”。 http://jsfiddle.net/V8LvC/ – Jawad 2011-05-26 17:43:39