[英]How can I apply a style using LESS to a nephew element of a class
I have these elements on the HTML: 我在HTML上有这些元素:
<div id="td-status" class="icongb-cancelled"></div>
<div class="ticket-header-text">
<span class="bet-text">TEXT1</span>
<span>TEXT2</span>
</div>
and I want to apply a certain style using LESS to TEXT1 ('bet-text' class) whether its uncle has a cercaion class (in this case icongb-cancelled). 我想对TEXT1(“ bet-text”类)使用LESS来应用某种样式,而其叔叔是否拥有cercaion类(在本例中为icongb-cancelled)。 I'd like to apply it also to TEXT2 (no class).
我也想将其应用于TEXT2(无类)。 Would it be possible?
这有没有可能?
I'm using this code, but it doesn't work: 我正在使用此代码,但是它不起作用:
.icongb_cancelled ~ .ticket-header-text {
& .bet-text {
color: #959595;
}
}
NOTE: I don't want to use JQuery to add or remove any class. 注意:我不想使用JQuery添加或删除任何类。 I want to make it just using LESS wihtout any modifying on the HTML.
我只想使用HTML进行任何修改就可以做到这一点。
Thanks in advance. 提前致谢。
EDIT: The code was fine, the problem was that I was using an underscore instead of a dash. 编辑:代码很好,问题是我使用下划线而不是破折号。 so you can use that code to apply a style to a nephew element.
因此您可以使用该代码将样式应用于侄子元素。
You're using .icongb_canceled
in the selector, but the class is icongb-canceled
. 您在选择器中使用
.icongb_canceled
,但是该类是icongb-canceled
。
Dash vs underscore . 短跑与下划线 。 They need to match.
他们需要匹配。
You can write .icongb-cancelled ~ .ticket-header-text .bet-text
, which is valid in CSS, but also is LESS compatible: 您可以编写
.icongb-cancelled ~ .ticket-header-text .bet-text
,它在CSS中有效,但与LESS兼容:
.icongb-cancelled ~ .ticket-header-text .bet-text { color: blue; } .icongb-cancelled ~ .ticket-header-text span { color: green; }
<div id="td-status" class="icongb-cancelled"></div> <div class="ticket-header-text"> <span class="bet-text">TEXT1</span> <span>TEXT2</span> </div>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.