如何在任何dom元素后面选择第二个div?

时间:2015-02-19 11:57:09

标签: css

如何将一个float left属性赋予h3之后的第二个div?

<div class="view-content">
  <h3>
  <div>
  <h3>
  <div>
  <h3>
  <div>
  <div>   this one !
  <h3>
 <div>
</div>

2 个答案:

答案 0 :(得分:1)

 .view-content div:nth-of-type(2) //Mistaken
 {
   float:left;
 }

它会解决你的问题。谢谢你指出错误

答案 1 :(得分:1)

您可以链接adjacent sibling selectors

h3 + div + div {
  float: left;
  background: yellow;
}

h3 + div {
  display: inline-block;
}
<div class="view-content">
  <h3></h3>
  <div>not this</div>
  <h3></h3>
  <div>nor this</div>
  <h3></h3>
  <div>or this</div>
  <div>but this one !</div>
  <h3></h3>
  <div>not this</div>
</div>