我有这段代码:
label.control-label{
font-weight: bold;
}
label.control-label::after{
content: ":";
}
这使得输入的Bootswatch Paper's标签变为粗体,并在标签后添加:
,并且效果非常好。然后我找到了一种创建浮动标签的方法:Paper description and example of floating labels并且,为了防止其他形式的行为更改,我将类.floating-labels
添加到表单之一并创建了这个CSS:
/* Based on Ryan Walters solution http://jsfiddle.net/RyanWalters/z9ymd852/
*/
/* --- material floating label --- */
form.floating-labels .form-group {
display: flex;
height: 55px;
}
form.floating-labels .control-label {
font-size: 16px;
font-weight: 400;
opacity: 0.4;
pointer-events: none;
position: absolute;
transform: translate3d(0, 22px, 0) scale(1);
transform-origin: left top;
transition: 240ms;
}
form.floating-labels .form-group.focused .control-label {
opacity: 1;
transform: scale(0.75);
}
form.floating-labels .form-control {
align-self: flex-end;
}
form.floating-labels .form-control::-webkit-input-placeholder {
color: transparent;
transition: 240ms;
}
form.floating-labels .form-control:focus::-webkit-input-placeholder {
transition: none;
}
form.floating-labels .form-group.focused .form-control::-webkit-input-placeholder {
color: #bbb;
}
它也有效并且不会使没有.floating-labels
类的表单混乱,除了一个错误 - :
也被添加到浮动标签,这看起来有点奇怪。所以我想创建一个CSS选择器,它将label.control-label
中分配的所有form
与.floating-labels
类分开。我创建了这个CSS,但解决方案无法正常工作:
label.control-label:not(form.floating-labels label.control-label){
font-weight: bold;
}
label.control-label:not(form.floating-labels label.control-label)::after {
content: ":";
}
如果有人帮助我实现CSS选择器,我将非常高兴,除了label.control-label
内的所有form
和.floating-labels
之外,我将非常高兴 - 谢谢你提前。
代码段:
label.control-label:not(form.floating-labels label.control-label){
font-weight: bold;
}
label.control-label:not(form.floating-labels label.control-label)::after{
content: ":";
}
<form>
<label class='control-label'>Should has ':' and be bold</label>
<input>
</form>
<form class='floating-labels'>
<label class='control-label'>Should NOT be bold</label>
<input>
</form>
form:not(.floating-labels) label.control-label{
font-weight: bold;
}
form:not(.floating-labels) label.control-label::after{
content: ":";
}
答案 0 :(得分:2)
使用您已使用的>
:not()
选择器
form:not(.floating-labels) > label.control-label{
font-weight: bold;
}
form:not(.floating-labels) > label.control-label::after{
content: ":";
}
答案 1 :(得分:1)
您需要使用以下CSS来执行此操作。
form.floating-labels label.control-label {
font-weight: normal;
}
form.floating-labels label.control-label::after {
content:"";
}
以下是一个工作代码段。
label.control-label {
font-weight: bold;
}
label.control-label::after {
content: ":";
}
form.floating-labels label.control-label {
font-weight: normal;
}
form.floating-labels label.control-label::after {
content: "";
}
<form>
<label class='control-label'>Should has ':' and be bold</label>
<input>
</form>
<form class='floating-labels'>
<label class='control-label'>Should NOT be bold</label>
<input>
</form>