I am trying to style some form labels by selecting them with their 'for' attribute. But nothing is being picked up when I preview it in IE7. I'm doing this because I'd like to style them differently to each other, without adding to the existing markup.
我试图通过选择'for'属性来设置某些表单标签的样式。但是当我在IE7中预览时,没有任何东西被拾取。我这样做是因为我想在不添加现有标记的情况下对它们进行不同的设置。
So if my css looks like the following, I get nothing:
所以如果我的css看起来如下,我什么也得不到:
<style>
label[for="foo"] {
background: blue;
padding: 1em
}
</style>
<form>
<label for="foo"/>bar</label>
<input name="foo" type="text"/>
</form>
But if I change it to this, the styling works.
但是,如果我改变它,造型工作。
<style>
label[fro="foo"] {
background: blue;
padding: 1em
}
</style>
<form>
<label fro="foo"/>bar</label>
<input name="foo" type="text"/>
</form>
Have you seen this kind of problem before? Is there a problem with the way I'm writing the CSS, IE7, or something else?
你以前见过这种问题吗?我正在编写CSS,IE7或其他什么方式有问题吗?
2 个解决方案
#1
This user seems to have had the same problem you are having: here
这个用户似乎遇到了同样的问题:这里
He says that because "for" is a reserved word, it can't be used as a property name. But 'htmlFor' is the DOM property name associated with the for attribute
他说,因为“for”是一个保留字,所以它不能用作属性名。但'htmlFor'是与for属性关联的DOM属性名称
#2
Labels are paired with specific input fields, so is there any reason why you cannot use class instead of creating a multitude of selectors in your CSS for this purpose?
标签与特定的输入字段配对,那么为什么你不能使用类而不是在CSS中为这个目的创建多个选择器?
#1
This user seems to have had the same problem you are having: here
这个用户似乎遇到了同样的问题:这里
He says that because "for" is a reserved word, it can't be used as a property name. But 'htmlFor' is the DOM property name associated with the for attribute
他说,因为“for”是一个保留字,所以它不能用作属性名。但'htmlFor'是与for属性关联的DOM属性名称
#2
Labels are paired with specific input fields, so is there any reason why you cannot use class instead of creating a multitude of selectors in your CSS for this purpose?
标签与特定的输入字段配对,那么为什么你不能使用类而不是在CSS中为这个目的创建多个选择器?