本文介紹了更改輸入上的父 div[type=checkbox]:用 css 檢查的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!
問題描述
我可以弄清楚如何在選中復選框時更改父 div :(更改以下段落效果很好.
I can figure out how to make the parent div change when checkbox is checked :( Changing the following paragraph works fine.
在 Chrome 中嘗試了這種方法,但沒有運氣:
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 選擇父級(直到 CSS4),所以你必須使用 JS..
No way to select a parent with CSS only (until CSS4), so you must use JS..
查看這篇談論它的帖子這里.
See this post that talking about it here.
這篇關于更改輸入上的父 div[type=checkbox]:用 css 檢查的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!
【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!