I am trying to rebuild an old site with grid layout.
Everything went fine until I started to fill the page with content.
See the code snippet and images.
If the content of the article (3) is short, a gap appears between the article text and bottom (5).
As the content of the article becomes longer, a gap appears between the sidebar (2) and sidebar1 (4).
Only when the sidebar and article are equal in length, there are no gaps.
I need that the sidebar1 (4) with sidebar2 (6) will be pulled up to the last menu item in the sidebar, and the bottom (5) along with base (7) will be pulled up to the article text independently of its length. Is it possible to do this with grid-only approach and without (or with minor) changes in html.
I played with numbering, naming, and rearranging the grid items, added some spacer blocks but so far got the same outcome. Could someone point me in the right direction?
#page-wrapper {
display: grid;
max-width: 1280px;
margin: 0 auto;
justify-items: stretch;
align-items: start;
grid-gap: 5px;
background: #ccc;
grid-template-areas:
"header header"
"sidebar article"
"sidebar1 bottom"
"sidebar2 base"
"footer footer";
grid-template-columns: 320px 1fr;
grid-template-rows: auto;
}
#page-wrapper > div, header, article, footer {
border: 1px solid #888;
font-size: 1.2em;
min-height: 50px;
padding: 15px;
color: #fff;
}
li {
list-style: none;
}
header {
background: #557;
grid-area: header;
}
.sidebar {
background: #55a;
grid-area: sidebar;
/* align-self: stretch; */
}
article {
grid-area: article;
background: #755;
/* align-self: stretch; */
}
.sidebar1 {
grid-area: sidebar1;
background: #351;
}
.bottom {
grid-area: bottom;
background: #632;
}
.sidebar2 {
grid-area: sidebar2;
background: #125;
}
.base{
grid-area: base;
background: #33b;
}
footer{
grid-area: footer;
background: #376;
}
<!doctype html>
<html>
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<link rel="stylesheet" href="style.css" />
</head>
<body>
<div id="page-wrapper">
<header>
<h3>1 Header</h3>
</header>
<div class="sidebar">
2 <ul>
<li>Menu item </li>
<li>Menu item </li>
<li>Menu item </li>
<li>Menu item </li>
<li>Menu item </li>
<li>Menu item </li>
<li>Menu item </li>
<li>Menu item </li>
<li>Menu item </li>
<li>Menu item </li>
</ul>
</div>
<article>
3 <p>Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.</p>
</article>
<div class="sidebar1">4</div>
<div class="bottom">5</div>
<div class="sidebar2">6</div>
<div class="base">7</div>
<footer><h3>8 Footer</h3></footer>
</div>
</body>
</html>