Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Declaring CSS rules to apply only to a particular class

Tags:

html

css

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

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">
                ....

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.

like image 967
user1038814 Avatar asked Dec 21 '22 18:12

user1038814


2 Answers

Just use the descendant selector:

.datepicker-days table {
    /* this rule will only apply to `<table>` elements that are descendents of any element with class "datepicker-days" */
}
like image 61
Dai Avatar answered Feb 14 '23 10:02

Dai


.datepicker-days { /* Targets the div */ }

.datepicker-days table { /* targets all tables nested in the div */ }

.datepicker-days > table { /*targets only tables that are direct children on the div */ }
like image 35
Xhynk Avatar answered Feb 14 '23 08:02

Xhynk