我必须将红色背景应用于偶数位置的所有元素<EM>
段落的第一个子元素。你能帮帮我吗?
我试过了:
p:nth-child(even)>em:first-child{background-color:red;}
但它不起作用..
答案 0 :(得分:2)
试试这个:
p:nth-child(even) em{ font-weight: bold; background: red; }
答案 1 :(得分:0)
像这样改变:
p:nth-child(even)>em:nth-child(1){background-colour:red;}
或者这个:
p:nth-child(even)>em:first-child{background-colour:red;}
答案 2 :(得分:0)
此代码应该可以执行您想要的操作。
<p><em>first</em> <em>dasdas</em></p>
<p><em>first</em> <em>dasdas</em></p>
<p><em>first</em> <em>dasdas</em></p>
<p><em>first</em> <em>dasdas</em></p>
<p><em>first</em> <em>dasdas</em></p>
<p><em>first</em> <em>dasdas</em></p>
<p><em>first</em> <em>dasdas</em></p>
p:nth-child(even) > em:first-child{ background-color: red;}
http://jsfiddle.net/y5938zqm/1/
你有一些拼写错误:
firstichild
代替first-child
background-colour
代替background-color
(颜色不含u
)