css 所有 div 与直接子 div

发布于 2024-10-09 06:56:05 字数 496 浏览 0 评论 0原文

我有这样的结构:

<div class="Root">
    <div>ddddddd</div>
    <div>
        <div>pppppppppp</div>
        <div>pppppppppp</div>
    </div>
    <div>ddddddd</div>
<div>

我想在包含 ddddddddiv 上放置边框,并且我想在所有上设置文本颜色 < code>div 变为绿色。

有两条规则:

  1. 我不能添加 class 属性。
  2. 我必须编写以 .Root 开头的选择器。

有什么想法吗?

I have this structure:

<div class="Root">
    <div>ddddddd</div>
    <div>
        <div>pppppppppp</div>
        <div>pppppppppp</div>
    </div>
    <div>ddddddd</div>
<div>

I want to put borders on the divs that contain ddddddd, and I want to set the text color on all divs to green.

There are two rules:

  1. I can't add class attributes.
  2. I have to write selectors that start with .Root.

Any ideas?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

深爱成瘾 2024-10-16 06:56:05

实际上我正在搜索这个:

Selects the divs that are direct child of Root:

.Root > div {
    border: 1px solid red;
}

Selects all the divs under Root:

.Root div {
    color:green;
}

Actually I was searching this:

Selects the divs that are direct children of Root:

.Root > div {
    border: 1px solid red;
}

Selects all the divs under Root:

.Root div {
    color:green;
}
街道布景 2024-10-16 06:56:05

像这样的东西吗?

.Root > :first-child, .Root > :last-child { border: 1px solid red }
.Root { color: green; }

演示: http://jsfiddle.net/karim79/N5qFu/1/

我建议你要完成此操作: http://www.w3.org/TR/css3-selectors/< /a>

Something like this?

.Root > :first-child, .Root > :last-child { border: 1px solid red }
.Root { color: green; }

Demo: http://jsfiddle.net/karim79/N5qFu/1/

I would advise you to go through this: http://www.w3.org/TR/css3-selectors/

初与友歌 2024-10-16 06:56:05
.root {
border: 1px solid green;
}

为什么你不为其他 div 声明 class /id ?

.root {
border: 1px solid green;
}

Why are you not declaring class /id for other divs?

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文