2017-06-11 50 views
1

我试图弄清楚如何实现具有特定子级的父级类。据我可以告诉这是不可能的CSS3,但它可能与jQuery。如何设置具有特定子级的父级CSS类

这里是父类.home .x-navbar

这里是子类.x-btn-navbar

CSS我要添加到父类:

background: linear-gradient(to bottom, rgba(0, 0, 0, 0.8) 0%,rgba(0, 0, 0, 0.8) 50%,rgba(0, 0, 0, 0.8) 100%) !important; 
background: -webkit-linear-gradient(to bottom, rgba(0, 0, 0, 0.8) 0%,rgba(0, 0, 0, 0.37) 50%,rgba(0, 0, 0, 0) 100%) !important; 
background: linear-gradient(to bottom, rgba(0, 0, 0, 0.8) 0%,rgba(0, 0, 0, 0.8) 50%,rgba(0, 0, 0, 0.8) 100%) !important; 

什么jQuery代码将我需要实现影响一个父类的CSS时,它有一个特定的孩子?

回答

0
var defaultCssRule = "linear-gradient(to bottom, rgba(0, 0, 0, 0.8) 0%,rgba(0, 0, 0, 0.8) 50%,rgba(0, 0, 0, 0.8) 100%) !important"; 
var myWebkitRule = "-webkit-linear-gradient(to bottom, rgba(0, 0, 0, 0.8) 0%,rgba(0, 0, 0, 0.37) 50%,rgba(0, 0, 0, 0) 100%) !important"; 
$(".home .x-navbar .x-btn-navbar").parents(".x-navbar").css({ 
    "background": myCssRule, 
    "background": myWebkitRule 
}); 
0

我希望我能正确理解你的问题。我认为这是Jquery的代码,你将需要:

$(document).ready(function() { 
 
    var element = $(".x-btn-navbar").parent(); 
 
    element.css({"background": "linear-gradient(to bottom, rgba(0, 0, 0, 0.8) 0%,rgba(0, 0, 0, 0.8) 50%,rgba(0, 0, 0, 0.8) 100%) !important", 
 
"background":" -webkit-linear-gradient(to bottom, rgba(0, 0, 0, 0.8) 0%,rgba(0, 0, 0, 0.37) 50%,rgba(0, 0, 0, 0) 100%) !important"}); 
 
});

相关问题