我有一段代码:
label.control-label{
font-weight: bold;
}
label.control-label::after{
content: ":";
}它使布斯沃特纸标签用于输入粗体,并在标签后面添加:,并且工作得很好。然后,我找到了一种创建浮动标签的方法:浮动标签的纸张描述与实例,为了防止其他表单中的行为更改,我将类.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;
}除了一个错误--在浮动标签中添加了:,这看起来有点奇怪。因此,我想要创建CSS选择器,当这些label.control-label在form中分配给类.floating-labels时,它接受所有的CSS。我创建了这个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>解决方案,基于@Diego López的答复:
form:not(.floating-labels) label.control-label{
font-weight: bold;
}
form:not(.floating-labels) label.control-label::after{
content: ":";
}发布于 2015-03-17 11:46:45
在您已经使用的>选择器中尝试:not()选择器
form:not(.floating-labels) > label.control-label{
font-weight: bold;
}
form:not(.floating-labels) > label.control-label::after{
content: ":";
}发布于 2015-03-17 11:49:45
您需要使用下面的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>
https://stackoverflow.com/questions/29097512
复制相似问题