0
是否可以檢查元素的類,查看它是否存在,然後將樣式應用於其他類?如果元素B包含某個類,則在元素A上應用樣式
示例僞代碼:
if (.myClass .myBlock == true) {
.otherClass {
display:none
}
}
是否可以檢查元素的類,查看它是否存在,然後將樣式應用於其他類?如果元素B包含某個類,則在元素A上應用樣式
示例僞代碼:
if (.myClass .myBlock == true) {
.otherClass {
display:none
}
}
這是不可能在這種情況下。但是,您可以通過CSS的級聯特性獲得類似的結果。
應用類到您的網站的身體:
.another-class {
display: none; // hides .another-class by default
}
body.special-class {
.another-class {
display: block; // shows if the body contains .special-class
}
}
由於生成的輸出的特異性爲第二個規則走高,.another-class
元素將是可見的。
給後面的行類
利用+
選擇使我們能夠顯示行after
提到的類。這樣我們就可以樣式下拉菜單彈出,給我們有以下HTML:
.popup {
display: none;
}
.popup:hover {
display: block;
}
.container:hover + .popup {
display: block;
}
<div class="container">Hover me!</div>
<div class="popup">This is a popup!</div>
恐怕這纔是最有可能與CSS。
nope。這不可能 – Raviteja