label for[…] not recognised by IE8

2019-03-01 16:13发布

I have the css below:

span label[for=Length]
{
width: 90px; 
display: block;
text-align:right; 
margin-top: 2px;
margin-right: 5px;
}

with the html:

<span><label for="Length">Length:</label></span>
<span><input type=text id="Length"></span>

It doesn't work in IE8. label[for=...] is not recognised. Any workaround?

Thanks.


UPDATE

I do a mistake in my question so now I updated. Any solutions? Thanks!

5条回答
Root(大扎)
2楼-- · 2019-03-01 16:19
.label1
{
width: 90px; 
display: block;
text-align:right; 
margin-top: 2px;
margin-right: 5px;
}

<span>Length:</span>
<label class='label1' for='Length'><input type=text id="Length"></label>
查看更多
我只想做你的唯一
3楼-- · 2019-03-01 16:27

The element has to be a label in order to be able to match it as a label in css try this:

<label for="Length">Length:</label>
<span><input type=text id="Length"></span>
查看更多
The star\"
4楼-- · 2019-03-01 16:30

Add a <label> element with a for="Length" attribute.

(And make sure you have a Doctype that triggers Standards Mode)

查看更多
劳资没心,怎么记你
5楼-- · 2019-03-01 16:32

IE 8 (or IE 9 for that matter) does not support attribute selectors in Quirks Mode. This is why adding a suitable doctype declaration, as suggested in Quentin’s answer, fixes the issue on IE 8. The simplest doctype for the purpose is <!doctype html>.

On IE 7, nothing helps, as it simply lacks the support, instead of having it masked out in Quirks Mode.

It is thus safer to use an id attribute on the label element, e.g. <label id=foo for=Length>, and use an id selector, such as #foo, in CSS. Such selectors work on all CSS-enabled browsers.

查看更多
手持菜刀,她持情操
6楼-- · 2019-03-01 16:43

It works in IE8.. Not depends on the browser. Check the !doctype html for the file. Hence its an attribute, it works.

查看更多
登录 后发表回答