我正在试图弄清楚如何影响具有特定孩子的父类。据我所知,这对CSS3来说是不可能的,但jQuery可能是可能的。
这是父类.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 :(得分: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
});
答案 1 :(得分: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"});
});