Change parent div on input[type=checkbox]:checked with css(更改输入上的父 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 检查的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:更改输入上的父 div[type=checkbox]:用 css 检查


- Fetch API 如何获取响应体? 2022-01-01
- Quasar 2+Apollo:错误:找不到ID为默认的Apollo客户端。如果您在组件设置之外,请使用ProvideApolloClient() 2022-01-01
- 400或500级别的HTTP响应 2022-01-01
- addEventListener 在 IE 11 中不起作用 2022-01-01
- Flexslider 箭头未正确显示 2022-01-01
- 如何使用 JSON 格式的 jQuery AJAX 从 .cfm 页面输出查 2022-01-01
- CSS媒体查询(最大高度)不起作用,但为什么? 2022-01-01
- 使用RSelum从网站(报纸档案)中抓取多个网页 2022-09-06
- Css:将嵌套元素定位在父元素边界之外一点 2022-09-07
- 失败的 Canvas 360 jquery 插件 2022-01-01