【问题标题】:How to set css for first div, if there's no second div如果没有第二个 div,如何为第一个 div 设置 css
【发布时间】:2017-03-12 20:58:39
【问题描述】:

我想为 <div class="first"> 设置 border-bottom-left-radius 和 border-bottom-right-radius,前提是没有 <div class="second"> .

你知道怎么做吗?

【问题讨论】:

    标签: javascript jquery css sass


    【解决方案1】:

    仅使用 CSS 是不可能的。这是一个使用jQuery 的示例:

    if ($('.second').length == 0) {
        $('.first').css('border-radius', '0 0 2px 2px');
    }
    

    使用$('.second').length == 0 来检查,second 类的元素是否存在。你可以阅读更多关于jQuery's css() function on the documention的信息。

    【讨论】:

      【解决方案2】:

      也许你会这样做:

      .first:last-of-type{ border-radius: 0 0 2px 2px; }

      如果第一个 div 是唯一的,则仅应用样式。

      【讨论】:

        猜你喜欢
        • 2017-11-25
        • 1970-01-01
        • 2016-11-26
        • 2014-09-10
        • 2014-01-04
        • 2020-01-28
        • 2019-10-07
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多