本文介紹了更改輸入上的父 div[type=checkbox]:用 css 檢查的處理方法,對(duì)大家解決問題具有一定的參考價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)吧!
問題描述
我可以弄清楚如何在選中復(fù)選框時(shí)更改父 div :(更改以下段落效果很好.
I can figure out how to make the parent div change when checkbox is checked :( Changing the following paragraph works fine.
在 Chrome 中嘗試了這種方法,但沒有運(yùn)氣:
Tried this approach without luck in Chrome:
HTML
?<div>
<input type="checkbox??????????????????????????????" checked>
<p>Test</p>
</div>???????????????????????????????????????????????
CSS
div {
background: pink;
width: 50px;
height:50px;
}
div + input[type=checkbox]:checked {
background: green;
}
input[type=checkbox]:checked + p {
background: blue;
}
http://jsfiddle.net/lajlev/3xUac/
推薦答案
沒有辦法只用 CSS 選擇父級(jí)(直到 CSS4),所以你必須使用 JS..
No way to select a parent with CSS only (until CSS4), so you must use JS..
查看這篇談?wù)撍奶舆@里.
See this post that talking about it here.
這篇關(guān)于更改輸入上的父 div[type=checkbox]:用 css 檢查的文章就介紹到這了,希望我們推薦的答案對(duì)大家有所幫助,也希望大家多多支持html5模板網(wǎng)!
【網(wǎng)站聲明】本站部分內(nèi)容來源于互聯(lián)網(wǎng),旨在幫助大家更快的解決問題,如果有圖片或者內(nèi)容侵犯了您的權(quán)益,請(qǐng)聯(lián)系我們刪除處理,感謝您的支持!