2017-06-11 55 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"}); 
 
});

相關問題