Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

I did simple grid but it is looks like styles is applying but grid is not working correct. All grid items have wrong width and height but css is applied. Stackblitz Why is that? How to fix that?

app.component.html

<header>Header</header>
<nav>Nav</nav>
<main>
  <section>Intro</section>
  <article>Cake</article>
  <article>Cake</article>
  <article>Cake</article>
</main>
<aside>Aside</aside>
<footer>Footer</footer>

app.component.css

.grid-item,
header,
main,
nav,
aside,
footer{
background: #044BD9;
color: white;
border: 1px solid #377EFF;
}

header{
    grid-column-start: 1;
    grid-column-end: 4;
}
footer{
    grid-column-start: 1;
    grid-column-end: 4;
}

styles.css

*{
    font-family: Arial, Helvetica, sans-serif;
    font-weight: 600;
    box-sizing: border-box;
}

html,body{
    background: #07038C ;
    margin: 0;
    height: 100%;
}

body{
    display: grid;
    grid-template-columns: 15em auto 15em;
    grid-template-rows: min-content auto min-content;
}

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
793 views
Welcome To Ask or Share your Answers For Others

1 Answer

Because the component comes in a wrapper <my-app _nghost-mfj-c40="" ng-version="10.0.9"> which does not have display:grid. I'd suggest body > * instead of just body...?

.grid-item,
header,
main,
nav,
aside,
footer {
  background: #044BD9;
  color: white;
  border: 1px solid #377EFF;
}

header {
  grid-column-start: 1;
  grid-column-end: 4;
}

footer {
  grid-column-start: 1;
  grid-column-end: 4;
}

* {
  font-family: Arial, Helvetica, sans-serif;
  font-weight: 600;
  box-sizing: border-box;
}

html,
body {
  background: #07038C;
  margin: 0;
  height: 100%;
}

body>* {
  display: grid;
  grid-template-columns: 15em auto 15em;
  grid-template-rows: min-content auto min-content;
}
<my-app>
  <header>Header</header>
  <nav>Nav</nav>
  <main>
    <section>Intro</section>
    <article>Cake</article>
    <article>Cake</article>
    <article>Cake</article>
  </main>
  <aside>Aside</aside>
  <footer>Footer</footer>
</my-app>

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...