Html 我怎样才能得到一个 css 伪元素 :checked 在没有 Javascript 的情况下在 IE8 中工作?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/17869547/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How can I get a css pseudo element :checked to work in IE8 without Javascript?
提问by nthChild
I have two radio buttons, I need to set the background color on click. My code works in all browsers except for IE8. Is this possible to get this to work for IE8 without the use of Javascript?
我有两个单选按钮,我需要在点击时设置背景颜色。我的代码适用于除 IE8 之外的所有浏览器。这是否可以在不使用 Javascript 的情况下使其适用于 IE8?
<form>
<input type="radio" id="m" name="gender" value="male">
<label for="m">male</label>
<input type="radio" id="f" name="gender" value="female">
<label for="f">female</label>
</form>
input:checked + label{
background:red;
}
回答by Renato
While IE8 understandsadjacent sibling selectors, it doesn't understandthe checked
pseudo-element, so, unfortunately, you can't make your code IE8-friendly by using CSS only.
尽管IE8理解相邻同胞选择,它不理解的checked
伪元素,所以,很遗憾,你不能让你的代码IE8友好仅使用CSS。
Take a look at Selectivizror IE7.jsfor a JavaScript solution.
查看Selectivizr或IE7.js以获得 JavaScript 解决方案。
回答by Janrider
You can try this:
你可以试试这个:
input[checked=checked] + label{
background:red;
}