第一个孩子的CSS没有工作

时间:2016-01-07 12:32:15

标签: html css css-selectors

<div class="parent-div">
 
 <p>
  <b>1. Some dummy text</b><br>
  <b>2. Some other dummy text</b><br>
  <b>3. Some other more dummy text</b><br>
 </p>

 <p>
  <b>4. Some dummy text</b><br>
  <b>5. Some other dummy text</b><br>
  <b>6. Some other more dummy text</b><br>
 </p>

</div>

我想隐藏第一个<b>标签并写道:

.parent-div b:first-child {display:none;}

但它不起作用。

3 个答案:

答案 0 :(得分:4)

问题在于.parent-div b:first-child {display:none;}您隐藏了每个<p>元素的第一个b标记。要仅隐藏第一个<b>中的第一个<p>,您可以使用.parent-div p:first-child b:first-child {display:none;}

&#13;
&#13;
.parent-div p:first-child b:first-child {display:none;}
&#13;
<div class="parent-div">
 
 <p>
  <b>1. Some dummy text</b><br>
  <b>2. Some other dummy text</b><br>
  <b>3. Some other more dummy text</b><br>
 </p>

 <p>
  <b>4. Some dummy text</b><br>
  <b>5. Some other dummy text</b><br>
  <b>6. Some other more dummy text</b><br>
 </p>

</div>
&#13;
&#13;
&#13;

答案 1 :(得分:1)

&#13;
&#13;
.parent-div > p b:first-child {display:none;}
&#13;
<div class="parent-div">
 
 <p>
  <b>1. Some dummy text</b><br>
  <b>2. Some other dummy text</b><br>
  <b>3. Some other more dummy text</b><br>
 </p>

 <p>
  <b>4. Some dummy text</b><br>
  <b>5. Some other dummy text</b><br>
  <b>6. Some other more dummy text</b><br>
 </p>

</div>
&#13;
&#13;
&#13;

答案 2 :(得分:1)

更改css

.parent-div p b:first-child {display:none;}