【问题标题】:How to stylize parent CSS class which has a specific child [duplicate]如何样式化具有特定子级的父 CSS 类 [重复]
【发布时间】:2017-11-13 04:10:46
【问题描述】:

我试图弄清楚如何影响具有特定孩子的父类。据我所知,这在 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?

【问题讨论】:

    标签: jquery html css background


    【解决方案1】:
    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
    });
    

    【讨论】:

      【解决方案2】:

      希望我能正确理解您的问题。我认为这是您需要的 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"});
       });

      【讨论】:

        猜你喜欢
        • 2012-01-21
        • 2022-08-17
        • 1970-01-01
        • 2014-01-27
        • 2014-01-30
        • 2012-07-17
        • 2012-10-06
        • 1970-01-01
        相关资源
        最近更新 更多