1

I am having issue with display: grid. I want header top and 33% width sidebar column and 66% for content. And I have declared grid-area. Can you help me?

.head {
  grid-area: head;
  background: tomato;
}

.side {
  grid-area: side;
  background: purple;
}

.content {
  grid-area: content;
  background: orange;
}

body {
  margin: 0;
}

* {
  box-sizing: border-box;
}

.wrapper {
  display: grid;
  grid-gap: 10px;
  grid-template-areas:
    "head head head"
    "side" "content content"
}

.box {
  padding: 20px;
  height: 100px;
}
<div class="wrapper">
  <div class="box head">
  </div>
  <div class="box side">
  </div>
  <div class="box content">
  </div>
</div>

2
  • The accepted answer hits the nail on the head. But also note that "head head head" "side" "content content" is invalid code. String values for grid-template-areas must all have an equal number of columns, or the rule is ignored. stackoverflow.com/q/45647833/3597276 Commented Apr 25, 2018 at 15:06
  • Ok noted.. Thanks Mate Commented Apr 26, 2018 at 4:48

1 Answer 1

5

Just move the content next to the sidebar

.head {
  grid-area: head;
  background: tomato;
}

.side {
  grid-area: side;
  background: purple;
}

.content {
  grid-area: content;
  background: orange;
}

body {
  margin: 0;
}

* {
  box-sizing: border-box;
}

.wrapper {
  display: grid;
  grid-gap: 10px;
  grid-template-areas:
    "head head head"
    "side content content"
}

.box {
  padding: 20px;
  height: 100px;
}
<div class="wrapper">
  <div class="box head">
  </div>
  <div class="box side">
  </div>
  <div class="box content">
  </div>
</div>

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.