2017-05-14 6 views
1

daypicker、monthpicker、yearpickerを内部コンポーネントとして持つngx-bootstrap datepickerを使用しています。私はデイピッカーの中にあるテーブルにCSSを適用したい。Angular2はコンポーネントセレクタの名前に基づいてCSSを適用します

<custom-datepicker> 

<datepicker> //ngx-bootstrap datepicker component 
    <daypicker> 
     <table> 
      //rows, want to apply some css to only this table 
     </table> 
    </daypicker> 
    <monthpicker> 
     <table> 
      //rows 
     </table> 
    </monthpicker> 
    <yearpicker> 
     <table> 
      //rows 
     </table> 
    </yearpicker> 
</datepicker> 

</customdatepicker> 

CustomDatePickerComponent.ts

@Component({ 
    selector: 'custom-datepicker', 
    templateUrl: 'custom-datepicker-component.html', 
    styleUrls: ['custom-datepicker-component.scss'], 
}) 

export class CustomDatePickerComponent { 

} 

カスタムDatePickerの-component.html

<datepicker></datepicker> 

カスタムDatePickerの-component.scss

//I want to apply this css to a table which is inside daypicker. As of now it's applying to all the tables 
table { 
    border: 1px solid lightgrey; 
} 
+1

'/ deep /'を見てください。 –

答えて

1

あなたがあなたのテーブルにCSSクラスを追加することができます。

<datepicker> //ngx-bootstrap datepicker component 
    <daypicker> 
     <table class="new-class"> 
      //rows, want to apply some css to only this table 
     </table> 
    </daypicker> 
... 
をして、通常のクラスセレクタを使用します。

.new-class { 
    // your styling 
} 

またそのようなあなたの日付ピッカーまたはdaypickerにクラスを追加します。

<datepicker class="new-class"> 
... 

子孫セレクタを使用:

.new-class table { 
    // your styling 
} 
+0

日付ピッカーコンポーネントはngx-bootstart datepickerライブラリからのもので、何も追加/変更できません。 –

+0

cssクラスを追加してもコンポーネント自体は変更されません。この場合、それはCSSエンジンがそれを選択するための単なるフラグです。私の答えはscssを使用した場合は考慮しません。 – ronenmiller

1

は、それは我々がCSS適用することができ、自己のコンポーネント名を使用して、このような単純なのです

カスタムDatePickerの-component.scss

daypicker { 
    table { 
    border: 1px solid red; 
    } 
} 
0

あなたはこの試みることができます:

datepicker > daypicker > table { 
    border: 1px solid lightgrey; 
} 
関連する問題