简体   繁体   中英

How to get Angular's <router-outlet> to work with CSS Grid

I'm trying to create a layout with Angular 7 and CSS Grid. The problem I have is that the router-outlet only takes up one column in the second row.

I have created a StackBlitz here .

As you can see in app.component.css I want router-outlet (and any of its content) to take up grid-column: 2 / 5 , as of now it takes up 2 / 3.

Is what I'm trying to achieve possible?

<router-outlet> has no size and does not have any content in it, the actual router content is the next element to it. Remove the styles from <router-outlet> and only apply it to the next element to that and you should be fine.

Also, your app.component tries to apply styles to components that are not included in your component. You have to specify this explicitly by using ViewEncapsulation.None in the component definition. See here: https://stackblitz.com/edit/angular-lmpnkl

I think the problem is that you are trying to apply the style directly to <router-outlet> . Instead, create a "main div" element and put the router outlet inside of it.

<app-header></app-header>
<app-navbar></app-navbar>
<div main>
  <router-outlet></router-outlet>
</div>
<app-footer></app-footer>

I've updated your stackblitz to demonstrate.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM