css - 如果验证失败,则设置 HTML5 输入类型的样式

标签 css html styling

大家好

我的问题很简单:我需要为无法验证的输入(如电子邮件)设置红色边框(或阴影?)的样式。是否有任何新的 CSS 技巧可以做到这一点?

如果您仍然不明白我在告诉您什么,那么这是需要更改的颜色: enter image description here

最佳答案

参见 https://developer.mozilla.org/en/CSS/%3Ainvalid有关 Firefox 的详细信息,尽管可能没有“-moz”的部分也适用于其他浏览器:

The :invalid CSS pseudo-class is applied automatically to <input> elements whose contents fail to validate according to the input's type setting. This allows you to easily have invalid fields adopt an appearance that helps the user identify and correct errors.

By default, Gecko does not apply a style to the :invalid pseudo-class. However it does apply a style (a red "glow" using the box-shadow property) to the :-moz-ui-invalid pseudo-class, which applies in a subset of cases for :invalid.

关于css - 如果验证失败,则设置 HTML5 输入类型的样式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6911175/

相关文章:

html - 我怎样才能在我的 table 里做一个滚动?

html - 下拉菜单选项卡在 VS2010 上不起作用

javascript - Bootstrap v 3.2 组件显示(折叠水平面板)

javascript - 使用 JavaScript 从超链接加载时的默认下拉值

html - 为什么我不能在 CSS 中设置 Textarea 的样式?

html - 右侧边距不显示

html - 如何在垂直网站中使 div 部分响应

css - 使用::before 背景图像时移动设备(chrome)上的图像边框问题

html - 为页面设置背景颜色

html - 使用 CSS 从元素内的 h 文本中删除下划线