[英]Add Style on subclass with css or jquery
I wish I could add a style to all the classes below the first div, So when I move the mouse over我希望我可以为第一个 div 下面的所有类添加一个样式,所以当我将鼠标移到
all classes must stylize in this way:所有类都必须以这种方式风格化:
background-color:black !important;
color:white !important;
I can't make all the white writing with css我不能用 css 写出所有的白字
<div data-id="#hMS2r-2141" class="event-item-wrapper "> <article itemscope="" class="event-list post-2141 simple_event type-simple_event status-publish has-post-thumbnail hentry simple_event_category-eventi"> <div class="media"> <div class="media-left media-middle"> <div class="date-info"> <span class="date-month">May</span> <span class="date-day-year">11, 2018</span> </div> </div> <div class="media-body media-middle"> <div class="info-event"> <h3 class="entry-title">Corso Acquarello</h3> </div> <div class="entry-description">Lorem ipsum dolor sit amet, consectetuer adipiscing elit, sed diam nonummy ...</div> </div> </div> </article> </div>
To apply the styles to any child and subchild of the wrapper on hover do要将样式应用于悬停时包装器的任何子项和子项,请执行
.event-item-wrapper:hover * {
background-color:black !important;
color:white !important;
}
Here is a working jsfiddle .这是一个有效的jsfiddle 。
To apply the styles to specific children of the wrapper on hover, you need to list the specific classes like this要在悬停时将样式应用于包装器的特定子项,您需要像这样列出特定的类
.event-item-wrapper:hover .event-list,
.event-item-wrapper:hover .media,
.event-item-wrapper:hover .media-left,
.event-item-wrapper:hover .date-info,
.event-item-wrapper:hover .date-month {
background-color:black !important;
color:white !important;
}
Using Jquery and css :
Jquery:
$(document).ready(function(){
$(".event-item-wrapper").hover(function(){
$(this).addClass("Mydivadd");
});
});
Css:
<style>
.Mydivadd {
background-color:red !important;
color:white !important;
}
</style>
@Exolon @Exolon
Try this code it works:试试这个代码它的工作原理:
#MouseHover:hover{ background-color:black !important; color:white !important; }
<div data-id="#hMS2r-2141" class="event-item-wrapper" id="MouseHover"> <article itemscope="" class="event-list post-2141 simple_event type-simple_event status-publish has-post-thumbnail hentry simple_event_category-eventi"> <div class="media"> <div class="media-left media-middle"> <div class="date-info"> <span class="date-month">May</span> <span class="date-day-year">11, 2018</span> </div> </div> <div class="media-body media-middle"> <div class="info-event"> <h3 class="entry-title">Corso Acquarello</h3> </div> <div class="entry-description">Lorem ipsum dolor sit amet, consectetuer adipiscing elit, sed diam nonummy ...</div> </div> </div> </article> </div>
I hope above code will be useful for you.我希望上面的代码对你有用。
Thank you.谢谢你。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.