[英]HTML5 Input Validation images with CSS3
I am currently working on an HTML5 form and using CSS3 for the styling. 我目前正在处理HTML5表单,并使用CSS3进行样式设置。 I have added CSS for input:required and input:valid and input:invalid to make an image get shown inside the text box. 我为输入:必需和输入:有效和输入:无效添加了CSS,以使图像显示在文本框中。
Both the required and invalid CSS work fine but for some reason input:valid gets ignored and is just replaced with the same image as input:required. 必需的CSS和无效的CSS都可以正常工作,但是由于某些原因,input:valid会被忽略,只是被替换为与input:required相同的图像。
Below is the CSS that I have used 以下是我使用过的CSS
input:required.fields, textarea:required.fields, select:required.fields
{
background:url("images/asterix.png") no-repeat;
background-position: right;
width: 200px;
background-color: white;
}
input:focus:required:invalid.fields, textarea:focus:invalid.fields, select:focus:invalid.fields
{
background:url("images/error.png") no-repeat;
background-position: right;
width: 200px;
background-color: white;
opacity: 1.0;
}
Both CSS sections above work fine without any problems but its the CSS below that for some reason is not working. 上面的两个CSS部分都可以正常工作,没有任何问题,但是下面的CSS由于某种原因无法正常工作。
input:valid.fields, textarea:required:valid.fields, select:value.fields
{
background:url("images/tick.png");
background-position: right;
width: 200px;
background-color: white;
opacity: 1.0;
}
In case it was to do with the image not being found I made the invalid image be the tick.png image and this worked fine but the valid section never seems to get called. 万一它与找不到图像有关,我将无效图像设为tick.png图像,这可以正常工作,但似乎从未调用过有效部分。
Thanks for any help you can provide. 感谢您的任何帮助,您可以提供。
I just used the following on my form: 我只是在表单上使用了以下内容:
input[required]:invalid {
background: #efdee0 url(../images/invalid.png) no-repeat center right;
}
input[required]:valid {
background: #f3f8ed url(../images/valid.png) no-repeat center right;
}
but then my fields are all required (http://www.paul-ellis.co.uk/contact.htm) 但随后我的所有字段都是必填字段(http://www.paul-ellis.co.uk/contact.htm)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.