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!
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
idattribute on thelabelelement, e.g.<label id=foo for=Length>, and use anidselector, such as#foo, in CSS. Such selectors work on all CSS-enabled browsers.