Declaring CSS rules to apply only to a particular class

前端 未结 4 1552
小鲜肉
小鲜肉 2021-01-19 15:14

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 be

相关标签:
4条回答
  • 2021-01-19 15:55

    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" */
    }
    
    0 讨论(0)
  • 2021-01-19 15:57
    .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 */ }
    
    0 讨论(0)
  • 2021-01-19 16:01

    You would do the following:

    .datepicker-days table {
        Styles here;
    }
    

    This looks for <table> with the .datepicker-days class only

    0 讨论(0)
  • 2021-01-19 16:05

    If you only need to apply a specific style to one unique div, why not give it an id #

    0 讨论(0)
提交回复
热议问题