Maison >interface Web >tutoriel HTML ><H>中有2个链接元素,只对第一个元素附加CSS,第二个不附加,怎么写_html/css_WEB-ITnose
<style type="text/css">.test h3 a:first-child {background-color: #FF0000;}</style><div class="test"><H3><a href="#">abc</a> <a href="#">123</a></H3></div>
<style type="text/css">.test h3 a.first {background-color: #FF0000;}</style><div class="test"><H3><a href="#" class="first">abc</a> <a href="#">123</a></H3></div>
<style type="text/css">.test h3 a:first-child {background-color: #FF0000;}</style><div class="test"><H3><a href="#">abc</a> <a href="#">123</a></H3></div>
<style type="text/css">.test h3 a.first {background-color: #FF0000;}</style><div class="test"><H3><a href="#" class="first">abc</a> <a href="#">123</a></H3></div>
<style type="text/css">.test h3 a:first-child {background-color: #FF0000;}</style><div class="test"><H3><a href="#">abc</a> <a href="#">123</a></H3></div>
<style type="text/css">.test h3 a.first {background-color: #FF0000;}</style><div class="test"><H3><a href="#" class="first">abc</a> <a href="#">123</a></H3></div>
CSS 选择器参考
选择第二个
<style type="text/css">.test h3 a:nth-child(2) {background-color: #FF0000;}</style> <div class="test"><H3><a href="#">abc</a> <a href="#">123</a></H3></div>
<style type="text/css">.test h3 a:first-child {background-color: #FF0000;}</style><div class="test"><H3><a href="#">abc</a> <a href="#">123</a></H3></div>
<style type="text/css">.test h3 a.first {background-color: #FF0000;}</style><div class="test"><H3><a href="#" class="first">abc</a> <a href="#">123</a></H3></div>
<style type="text/css">.test1 .test2 h3 a:first-child {background-color: #FF0000;}.test1_2 .test2 h3 a:first-child {background-color: #EFEFEF;}</style><div class="test1"><div class="test2"><H3><a href="#" name="1">abc</a> <a href="#" name="2">123</a></H3></div></div><div class="test1_2"><div class="test2"><H3><a href="#" name="1">abc</a> <a href="#" name="2">123</a></H3></div></div>
<style type="text/css">.test1 .test2 h3 a:first-child {background-color: #FF0000;}.test1_2 .test2 h3 a:first-child {background-color: #EFEFEF;}</style><div class="test1"><div class="test2"><H3><a href="#" name="1">abc</a> <a href="#" name="2">123</a></H3></div></div><div class="test1_2"><div class="test2"><H3><a href="#" name="1">abc</a> <a href="#" name="2">123</a></H3></div></div>