添加一个类名到::-webkit

JuM*_*Gar 1 css

我正在尝试将类名添加到 webkit、moz、ms...我该如何转换它:

::-webkit-input-placeholder {
    text-align: center;
}

::-moz-placeholder { 
    text-align: center; 
}

::-ms-input-placeholder { 
    text-align: center;
}
Run Code Online (Sandbox Code Playgroud)

进入:

.form-horizontal {

::-webkit-input-placeholder {
    text-align: center;
}

::-moz-placeholder { 
    text-align: center; 
}

::-ms-input-placeholder { 
    text-align: center;
}

}
Run Code Online (Sandbox Code Playgroud)

谢谢。

Mic*_*ker 5

您只需将所需的类名放在选择器前面即可。如果您想像这样嵌套选择器,请使用预处理器。

.form-horizontal ::-webkit-input-placeholder {
    text-align: center;
}

.form-horizontal ::-moz-placeholder { 
    text-align: center; 
}

.form-horizontal ::-ms-input-placeholder { 
    text-align: center;
}
Run Code Online (Sandbox Code Playgroud)
<div class="form-horizontal">
  <input type="text" placeholder="centered">
</div>

<div>
  <input type="text" placeholder="non centered">
</div>
Run Code Online (Sandbox Code Playgroud)