我不知道为什么我的 a:first-child
不工作。这是我的 html:
<!DOCTYPE html>
<link href='http://fonts.googleapis.com/css?family=Geo' rel='stylesheet'>
<title>Mira's place</title>
<header>
<a href="index.html">Mira's place</a><br>
<h2>“<span id="quote">If nothing, then this.</span>”</h2>
<ul>
<li><a href="#">Home</a>
<li><a href="#">Games</a>
<li><a href="#">Pixel Art</a>
<li><a href="#">Contact</a>
</ul>
</header>
<section>
<h2>This is test H2</h2>
<p>This is lorem ipsum shitsum, blah <a href="#">Test</a> blah baldflksafdjsl adslkf ajfdlks ajfldsa jflksda lfhsdalf jdsalfh sdlfdshfdsk fjsdl ajfl
</section>
<footer>
<p>(C) MiraCZ 2013 - You can copy anything here!
</footer>
这是我的CSS
html {
background-color: #002240;
font-family: "Geo", sans-serif;
margin: 0;
}
header {
background-color: #001629;
margin: 0 -10px 0 -10px;
}
a:first-child {
color: #FF628C;
font-size: 36px;
}
header h2 {
color: #80FFBB;
}
li {
display: inline-block;
font-size: 18px;
}
p {
color: white;
}
我只想让第一个 a
大小为 36px。任何人都可以帮助为什么它会影响其他 a
吗?这是我的 jsfiddle http://jsfiddle.net/dsT4Z/
这是我看到的。我添加了红色箭头来显示哪些 a
我不想那么大等等。
最佳答案
所有 <a>
导航中的标签是包含 <li>
的第一个子元素标签,因此符合规则。
文本区域中的那个是包含 <p>
的第一个(元素)子元素, 因此符合规则。
在您实际想要影响的元素上使用 ID 或类名会容易得多。
关于html - 第一个 child 在我的代码中不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15990992/