Home >Web Front-end >HTML Tutorial >There are 2 link elements in
080b747a20f9163200dd0a7d304ba388
.test h3 a {background-color: #FF0000;}
531ac245ce3e4fe3d50054a55f265927
8672f64d388dd81df27260b4e858ab0d
9d67e4fe87d770f037d88ca428ebdeceee7959cc8dd4be16ef633321c03dac32abc5db79b134e9f6b82c0b36e0489ee08ed ee7959cc8dd4be16ef633321c03dac321235db79b134e9f6b82c0b36e0489ee08ed036fe202a55b5e84ed42b72960fef91d
16b28748ea4df4d9c2150843fecfba68
As above, there are 2 links in H3. I want to add a background color only to the first link A, and the second link has no style. How should it be modified?
<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 selector reference
Select the second one
<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>