|
| 1 | +I have following selector |
| 2 | + |
| 3 | +Note, a single space without comma means its a descendant selector relation. |
| 4 | + |
| 5 | +`.a .b` will select any B that are inside A, even if there are other elements between them. |
| 6 | + |
| 7 | +```css |
| 8 | +.ng-dropdown-panel .ng-dropdown-panel-items .ng-option { |
| 9 | + @include sdk-ng-select-typography-pad(); |
| 10 | + border-bottom: 1px solid #ebebeb; |
| 11 | + border-width: thin; |
| 12 | + |
| 13 | + &.ng-option-selected .ng-option-label { |
| 14 | + @include sdk-text-body(); |
| 15 | + } |
| 16 | + .ng-option-selected.ng-option-marked .ng-option-label { |
| 17 | + @include sdk-text-body(); |
| 18 | + } |
| 19 | + } |
| 20 | +``` |
| 21 | + |
| 22 | +But I want apply the above styles both for the above case which is below |
| 23 | + |
| 24 | +```css |
| 25 | +.ng-dropdown-panel .ng-dropdown-panel-items .ng-option { |
| 26 | + ...some styles |
| 27 | +} |
| 28 | +``` |
| 29 | + |
| 30 | +AND also for the below case, i.e. instead of ONLY `.ng-dropdown-panel` as above, I also want to capture the cases, when both classes are present, like below - and then the rest of the descendants follow |
| 31 | + |
| 32 | + `.ng-dropdown-panel.sdk-ng-select` |
| 33 | + |
| 34 | +which will be below |
| 35 | +```css |
| 36 | +.ng-dropdown-panel.sdk-ng-select .ng-dropdown-panel-items .ng-option { |
| 37 | + ...some styles |
| 38 | + |
| 39 | +} |
| 40 | +``` |
| 41 | + |
| 42 | +The brute force way would be to almost duplicate the above styles selectors with another like below. |
| 43 | + |
| 44 | + |
| 45 | +```css |
| 46 | + &.ng-dropdown-panel.sdk-ng-select .ng-dropdown-panel-items .ng-option { |
| 47 | + @include sdk-ng-select-typography-pad(); |
| 48 | + border-bottom: 1px solid #ebebeb; |
| 49 | + border-width: thin; |
| 50 | + |
| 51 | + &.ng-option-selected .ng-option-label { |
| 52 | + @include sdk-text-body(); |
| 53 | + } |
| 54 | + .ng-option-selected.ng-option-marked .ng-option-label { |
| 55 | + @include sdk-text-body(); |
| 56 | + } |
| 57 | + } |
| 58 | +``` |
| 59 | + |
| 60 | +But a much better way to do it is as below |
| 61 | + |
| 62 | +```css |
| 63 | + &.ng-dropdown-panel, |
| 64 | + &.ng-dropdown-panel.sdk-ng-select { |
| 65 | + .ng-dropdown-panel-items .ng-option { |
| 66 | + @include sdk-ng-select-typography-pad(); |
| 67 | + border-bottom: 1px solid #ebebeb; |
| 68 | + border-width: thin; |
| 69 | + |
| 70 | + &.ng-option-selected .ng-option-label { |
| 71 | + @include sdk-text-body(); |
| 72 | + } |
| 73 | + .ng-option-selected.ng-option-marked .ng-option-label { |
| 74 | + @include sdk-text-body(); |
| 75 | + } |
| 76 | + } |
| 77 | + } |
| 78 | +``` |
0 commit comments