css - 供应商前缀导致 css 失败

标签 css

我正在尝试将占位符设置为输入的样式。此规则在 FF 和 Chrome 中运行良好:

.b-required-missing input[type="text"]::placeholder,
.b-required-missing input[type="email"]::placeholder,
.b-required-missing textarea::placeholder {
     color: tomato;
 }

但是,如果我尝试使用 MS 或 webkit 的供应商前缀让它在 Edge 中工作(我在某处读到 Edge 响应 webkit 前缀):

.b-required-missing input[type="text"]::-ms-input-placeholder,
.b-required-missing input[type="email"]::-ms-input-placeholder,
.b-required-missing textarea::-ms-input-placeholder,
.b-required-missing input[type="text"]::placeholder,
.b-required-missing input[type="email"]::placeholder,
.b-required-missing textarea::placeholder{
    color: tomato;
}

这会在 firefox 中破坏它,即使我放置了 -moz- 供应商前缀。我怎样才能让它在所有 3 种浏览器中工作?

http://jsfiddle.net/vc8V4/516/

最佳答案

如果规则无效,浏览器将忽略样式。

所以 -moz- 在 Chrome 中是无效的。

不要使用单个规则,而是对每个前缀使用不同的规则:

.b-required-missing input[type="text"]::-ms-input-placeholder,
.b-required-missing input[type="email"]::-ms-input-placeholder,
.b-required-missing textarea::-ms-input-placeholder {
    color: tomato;
}

.b-required-missing input[type="text"]::placeholder,
.b-required-missing input[type="email"]::placeholder,
.b-required-missing textarea::placeholder{
    color: tomato;
}

这样第一条规则将失败,然后第二条规则将被应用

关于css - 供应商前缀导致 css 失败,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49196397/

相关文章:

javascript - 位置音频触发(HTML,CSS,skrollr,JS)

css - 如何减少 topnav 下的空白区域?

html - html 的屏幕分辨率问题

html - 即使不需要,元素也会在 bootstrap 4 导航栏中折叠

javascript - 我想在所有没有类 'block' 的 div 中附加提到的标签

html - 尝试在选中时更改自定义复选框标签的颜色,仅限 CSS

javascript - 如何使用 jquery ui 在日历中突出显示日期应用 anchor 标记

html - 完美的图像容器 : Centered, 宽高比,收缩和增长以适合

html - 递归 Angular 搞乱CSS

javascript - onclick 函数上的 CSS 选择器