.lt-ie9 类针对 IE6/7/8 —不支持 IE8
我有一个 form,它在每个字段中使用各种 PNG 图像,根据进展情况使用伪类进行切换填写该字段以及该字段是否不是验证必填字段。
IE 对伪类的支持几乎不存在,这并不是什么大问题,只要我可以在所有浏览器中显示基本图标,尽管无需切换以反映 IE6/7/8 中字段状态的变化。
但是,我对以下图像的 CSS 存在问题:
#contact input#url:empty,.lt-ie9 #contact input#url{background:url(url-icon.png) no-repeat left center;margin-bottom:24px}
基本上,仅使用 #contact input#url:empty
选择器,当页面在 IE6-8 中加载时,它根本不会显示。通过添加 .lt-ie9 #contact input#url
选择器,它可以在 IE6 和 IE7 中正确显示,但由于某种原因,在 IE8 中无法显示。
HTML 如下(CSS 位于:http://i.via.dj/EOma):
<div id="contact-form">
<form id="contact" class="clear" method="post" accept-charset="utf-8" novalidate="novalidate">
<fieldset>
<input type="text" name="checking" placeholder="[email protected]" class="hidden" id="checking">
<label for="checking" class="hidden">If you do not want to submit this form, enter your email in this field</label>
<p class="name">
<input type="text" name="name" placeholder="John Doe" title="Enter your name" required="required" id="name">
<label for="name">Name *</label>
<label class="error" for="name" id="name-error">Name is required</label>
</p>
<p class="email">
<input type="email" name="email" placeholder="[email protected]" autocapitalize="off" title="Enter your e-mail address" required="required" id="email">
<label for="email">Email *</label>
<label class="error" for="email" id="email-error">Type a valid email</label>
</p>
<p class="website">
<input type="url" name="url" placeholder="http://" autocapitalize="off" id="url">
<label for="url">Website</label>
</p>
<p class="message">
<textarea name="message" placeholder="Type your message here (max. length 1,200 characters)" title="Enter your comment or message" required="required" id="message" maxlength="1200"></textarea><label for="message">Message *</label>
<label class="error" for="message" id="message-error">You haven't typed a message</label>
</p>
<p class="submit">
<input type="submit" value="Send message" />
</p>
</fieldset>
</form>
任何建议都非常感激。
I have a form that uses various PNG images in each field, which switch using pseudo classes depending on the progress made in filling it in and whether the field is not a required one for validation.
The near-non-existent IE support for pseudo-classes isn't a deal breaker, providing I can make the basic icons display in all browsers—albeit without switching to reflect changes in field status in IE6/7/8.
I am, however, having an issue with the CSS for the following image:
#contact input#url:empty,.lt-ie9 #contact input#url{background:url(url-icon.png) no-repeat left center;margin-bottom:24px}
Basically, with just the #contact input#url:empty
selector, it doesn't display at all when the page loads in IE6-8. By adding the .lt-ie9 #contact input#url
selector, it displays properly in IE6 and IE7 but not, for some reason, in IE8.
Here's the HTML (the CSS is available here: http://i.via.dj/EOma):
<div id="contact-form">
<form id="contact" class="clear" method="post" accept-charset="utf-8" novalidate="novalidate">
<fieldset>
<input type="text" name="checking" placeholder="[email protected]" class="hidden" id="checking">
<label for="checking" class="hidden">If you do not want to submit this form, enter your email in this field</label>
<p class="name">
<input type="text" name="name" placeholder="John Doe" title="Enter your name" required="required" id="name">
<label for="name">Name *</label>
<label class="error" for="name" id="name-error">Name is required</label>
</p>
<p class="email">
<input type="email" name="email" placeholder="[email protected]" autocapitalize="off" title="Enter your e-mail address" required="required" id="email">
<label for="email">Email *</label>
<label class="error" for="email" id="email-error">Type a valid email</label>
</p>
<p class="website">
<input type="url" name="url" placeholder="http://" autocapitalize="off" id="url">
<label for="url">Website</label>
</p>
<p class="message">
<textarea name="message" placeholder="Type your message here (max. length 1,200 characters)" title="Enter your comment or message" required="required" id="message" maxlength="1200"></textarea><label for="message">Message *</label>
<label class="error" for="message" id="message-error">You haven't typed a message</label>
</p>
<p class="submit">
<input type="submit" value="Send message" />
</p>
</fieldset>
</form>
Any suggestions much appreciated.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
其中的选择器不会按照您的预期运行:
低于 9 的 IE 不支持
:empty
,因此上面的整个规则将(或应该..)在所有低于 9 的 IE 版本中都被完全忽略。我不确定为什么它在 IE7 中仍然适用。 IE7 太疯狂了。
来自规范:
要解决您的问题,请尝试将其分为两个规则:
The selector in this isn't going to behave as you're expecting:
:empty
isn't supported in IE lower than 9, so the entire rule above will (or should..) be completely ignored in all versions of IE lower than 9.I'm not sure why it would still be working for you in IE7. IE7 is crazy.
From the spec:
To fix your problem, try splitting it up into two rules: