本文介紹了CSS所有div與直接子div的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!
問題描述
我有這個結構:
<div class="Root"><div>ddddddd</div><div>pppppppppp</div><div>pppppppppp</div></div><div>ddddddd</div>我想在包含 dddddddd
的 div
上設置邊框,并且我想在 all 上設置文本顏色div
s 變為綠色.
有兩條規則:
- 我無法添加
class
屬性. - 我必須編寫以
.Root
開頭的選擇器.
有什么想法嗎?
解決方案 其實我在找這個:
選擇作為 Root 的直接子級的 div:
.Root >分區 {邊框: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;
}
這篇關于CSS所有div與直接子div的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!
【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!