定位不带类或ID的div [英] target a div without a class or id

查看:52
本文介绍了定位不带类或ID的div的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有人知道我如何定位div并设置其样式(当它位于另一个div中并且没有id或类时).

Does any one know how I can target a div, and style it, when it is in another div and it has no id or class.

<div class="wrapper">
    <div>
    </div>

    <div>
    </div>

    <div>
    </div>
</div>

例如,我如何定位div二.

How do I target div two for example.

推荐答案

.wrapper > div:nth-child(1) {
  //css rules for a div that is the first child of .wrapper
}

.wrapper > div:nth-child(2) {
  //css rules for a div that is the second child of .wrapper
}

请注意>是必需的,否则它将以任何后代div(孙子等)为目标,而不是直接子目标.

Note the > is necessary, otherwise it will target any descendent divs (grandchildren, etc) instead of just direct children.

这篇关于定位不带类或ID的div的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆