声明CSS规则仅应用于特定类 [英] Declaring CSS rules to apply only to a particular class

查看:121
本文介绍了声明CSS规则仅应用于特定类的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下CSS,我只需要应用到一个特定的div(因为冲突):

I have the following CSS I need to apply to only a particular div (because of conflicts):

有问题的div有类名称datepicker-days。我将以下声明为 .datepicker-days.table ?但是如何声明 .table 类下面呢?

The div in question has the class name datepicker-days. Do I declare the below table as .datepicker-days.table? But then how do I declare the .table class below that?

CSS

    table {
      max-width: 100%;
      border-collapse: collapse;
      border-spacing: 0;
    }
    .table {
      width: 100%;
      margin-bottom: 18px;
    }
    .table th, .table td {
      padding: 8px;
      line-height: 18px;
      text-align: left;
      border-top: 1px solid #ddd;
    }

HTML

<div class="datepicker-days" style="display: block; ">
      <table class=" table-condensed">
         <thead>
             <tr>
                <th class="prev">
                ....

对不起,如果这不清楚,CSS规则是引导。我只是使用一些规则,因为我使用的datepicker插件取决于这些特定的规则。所以,在我的代码中有其他实例< tables> ,我不希望应用这些规则。

Sorry if this wasn't clear, the CSS rules are from Bootstrap. I'm just using a few of the rules because the datepicker plugin I am using depends on those particular rules. So where I have other instances of <tables> in my code, I don't want these rules to apply.

推荐答案

只需使用后代选择器:

.datepicker-days table {
    /* this rule will only apply to `<table>` elements that are descendents of any element with class "datepicker-days" */
}

这篇关于声明CSS规则仅应用于特定类的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆