本文介紹了CSS所有div與直接子div的處理方法,對(duì)大家解決問題具有一定的參考價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)吧!
問題描述
我有這個(gè)結(jié)構(gòu):
<div class="Root"><div>ddddddd</div><div>pppppppppp</div><div>pppppppppp</div></div><div>ddddddd</div>我想在包含 dddddddd
的 div
上設(shè)置邊框,并且我想在 all 上設(shè)置文本顏色div
s 變?yōu)榫G色.
有兩條規(guī)則:
- 我無法添加
class
屬性. - 我必須編寫以
.Root
開頭的選擇器.
有什么想法嗎?
解決方案 其實(shí)我在找這個(gè):
選擇作為 Root 的直接子級(jí)的 div:
.Root >分區(qū) {邊框:1px 純紅色;}
選擇 Root 下的所有 div:
.Root div {顏色:綠色;}
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 div
s that contain ddddddd
, and I want to set the text color on all div
s to green.
There are two rules:
- I can't add
class
attributes.
- I have to write selectors that start with
.Root
.
Any ideas?
解決方案 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;
}
這篇關(guān)于CSS所有div與直接子div的文章就介紹到這了,希望我們推薦的答案對(duì)大家有所幫助,也希望大家多多支持html5模板網(wǎng)!
【網(wǎng)站聲明】本站部分內(nèi)容來源于互聯(lián)網(wǎng),旨在幫助大家更快的解決問題,如果有圖片或者內(nèi)容侵犯了您的權(quán)益,請(qǐng)聯(lián)系我們刪除處理,感謝您的支持!