I'm currently recreating a very basic website I implemented in React beforehand in Angular. However, after getting the logic and the template working correctly, I immediately noticed that the CSS is not being applied correctly, with only small parts working.
Here's the template:
<div className="container text-center">
<h2>Konzerte</h2><br/><br/><br/>
<div class="row">
<div class="col-sm-4" *ngFor="let concert of concerts">
<a className="concertItem" href="#">
<p><strong>
{{concert.name}}
</strong><br/>
</p>
<img class="concertImg" src="assets/bandmember.jpg" alt="Random Name" width="150" height="150">
</a>
<p>
{{concert.events[0]}}<br/>
{{concert.events[1]}}
</p>
</div>
</div>
</div>
And here are the styles:
.container {
margin-top: 6em;
margin-bottom: 6em;
padding: 40px 120px;
background: lightgrey;
border-radius: 24px;
}
a.concertItem {
text-decoration: none;
color: black;
}
.concertImg {
border: 10px solid transparent;
}
.concertImg:hover {
border-color: darkgrey;
}
I'm also using bootstrap in my index.html. I'd imagine it would have something to do with loading order, but I'm not sure how to fix it. Stuff like the grey border on hover works, but the entire site is not centered and for example the background is missing.
Thanks in advance for any suggestions!
It could be the loading order, make sure your customizations to all the framework nonsense loads LAST.
Though it could also be specificity hell -- something in ONE of those malfing frameworks being declared with a different level of specificity (ID trumping a class, they derped !important in out of incompetence) given you problems.
Have you tried investigating with a document inspector to see what order things are being applied in, IF the styles you are declaring are being applied, and if it's not appearing what OTHER styles might be overriding it?
Though that markup... gah. what I expect though given the list of frameworks you said you're using...
Angular features a couple of view encapsulations, which provide support for Shadow DOM. The available modes are
ViewEncapsulation.Native,ViewEncapsulation.Emulated, andViewEncapsulation.None; the default isEmulated.In
NativeandEmulatedmodes, what this means is that a style file is isolated only to the component that references the style in itsstyleUrlslist. So any styles that you defined in app.component.css will only apply toAppComponentand not to its ancestors or the their siblings. Component styles also do not automatically apply to child components unless you use shadow-piercing.To correct your problem, one thing you could do is to change the view encapsulation on your component to
None. Any styles in this component will now leak out to the rest of the page. Example:@Component({ selector: 'app-component', encapsulation: ViewEncapsulation.None }) export class AppComponent {}The other thing to do would be to place shared styles outside of Angular in the main page. If you're using the Angular CLI, you can add styles to the
stylesproperty in the .angular-cli.json configuration file.