Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
122 views
in Technique[技术] by (71.8m points)

javascript - CSS grid is being ignored

Hi I'm still relatively new to HTML and CSS at just a few weeks of practice and I had some success using grids on previous projects but am now stuck as it appears when I try to use grid: display; it is currently being ignored.

#container{
  display: grid;
  grid-template-areas:
    "navbar content";
  grid-auto-flow: column;
  grid-template-columns: 1fr 3fr;
  justify-content: center;
}
#main-doc{
 
}
#main-title{
  grid-area: content;
  background-color: gray;
  grid-column-start: 1;
  grid-column-end: 3;
}
}
#navtitle{
  grid-area: navbar;
  
}
<body>
  <main id="main-doc">
    <div id="container">
    <h1 id="main-title">main doc</h1>
    <nav id="navtitle">Title</nav>
    </div>
  </main>
  

</body>
question from:https://stackoverflow.com/questions/65642589/css-grid-is-being-ignored

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

1 Reply

0 votes
by (71.8m points)

By removing the grid-column-start and grid-column-end from the #main-title, you can achieve the desired result:

#container{
  display: grid;
  grid-template-areas:
    "navbar content";
  grid-auto-flow: column;
  grid-template-columns: 1fr 3fr;
  justify-content: center;
}
#main-title{
  grid-area: content;
  background-color: gray;
}
#navtitle{
  grid-area: navbar;
}
<body>
  <main id="main-doc">
    <div id="container">
      <h1 id="main-title">main doc</h1>
      <nav id="navtitle">Title</nav>
    </div>
  </main>
</body>

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...