J'ai 5 composants tous ont le même pied de page
<app-footer style="margin-top: 0"></app-footer>
Dans le composant de pied de page, il y a une ligne de code
footer { margin-top: 0 !important }
En tout les 4 composants cela fonctionne très bien. Mais dans le 5ème composant où j'utilise le pied de page je n'ai pas besoin du haut de la marge.
Donc, dans le 5ème composant, j'ai essayé
footer {
margin-top: 80px;
}
et
<app-footer></app-footer>
Mais cela ne fonctionne pas.
3 Réponses :
Utilisez: pseudo-classe hôte,
Essayez ceci:
footer.component.css
<app-footer class="withoutpadding"></app-footer> <app-footer ></app-footer>app.component.html
:host(.withoutpadding) .footer{ color:red; padding: 0px; } .footer{ padding: 10px; border:1px solid red; }
L'ajout de composant parent p> app-footer.component.ts app.footer.component .html app.component.css style = "margin-top: 0;" ne fonctionnera pas car vous attribuez au composant app-footer un code margin-top > tandis que la balise footer dans le composant contiendra toujours le style margin-top: 80px; . Vous pouvez passer une vérification au composant app-footer et ajouter conditionnellement le margin-top: 80px; style .margin-top {
margin-top: 80px;
}
<footer [ngClass]="{'margin-top': showMargin}">
// ...
</footer>
@Input showMargin: boolean;
<app-footer [showMargin]="true"></app-footer>
Essayez-le comme ceci
<hello [ngStyle]="{overflow: 'scroll', color:'red',margin:80 +'px'}"></hello>
utilisez class au lieu de style si vous voulez utiliser alors le code correct serait