app.component.html
<div>
<app-cards *ngFor=" let card of cards; index as i;
first as isFirst; last as isLast; odd as isOdd; even as isEven"
[cardIndex]="i+1" (outputValue)="onCardSelected($event)" [inputValue]="card"
[class.isFirst]="isFirst" [class.isEnd]="isLast" [class.isOdd]="isOdd" [class.isEven]="isEven">
</app-cards>
</div>
cards.component.html
<div>
<h1>{{index + '. ' + webSeries.name}}</h1>
<img [src]="webSeries.image" />
<button (click)="onWebSeriesView()">Watch Series</button>
</div>
app.component.css
app-cards.isFirst{
border: 1rem solid black;
padding: 1rem;
}
Output is :-
CSS Border & Padding is not applied properly. Am I doing anything wrong?
2
Answers
Assuming
isFirst
boolean is true then just having the CSS selector should work:You may need to consider adding
!important
to styles to override defaults.If you want to target add space before the selector:
Read more about descendant selector here: https://developer.mozilla.org/en-US/docs/Web/CSS/Descendant_combinator
By defect a component has
display:inline
. So you need take acount about this. generally you can simply add, e.g.display:block
ordisplay:inline-block
.