Answered
Layout using Grid - Cols & rows spill over container problem
Hello
Why do the columns and rows spill over 'container' before and when you resize the browser window?
Plus how to get the 'Sidebar' 'main' 'content1' thru 'content5' columns to drop down from each other when resized?
How to add the 'content4 and content5 under the grid-template-columns and
grid-template-columns rows?
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Grid Layout 4 col</title>
<meta name="viewport" content="width=device-width, initial-scale=1">
<style>
@import url('https://fonts.googleapis.com/css2?family=Open+Sans&display=swap');
body {
background-color: #5F9EA0;
margin: 40px;
padding: 0px;
}
.container {
width: 85%;
display: grid;
height: 90vh;
grid-template-columns: .70fr .80fr .90fr 1.5fr;
/* sidebar, content1, content2, content3 */
grid-template-rows: 0.4fr 2.0fr 1.2fr 1fr;
/* height: nav, main, content, footer */
grid-template-areas: "nav nav nav nav "
"sidebar main main main"
"sidebar content1 content2 content3"
"footer footer footer footer";
grid-gap: 6px;
font-size: 12px;
@media only screen and (max-width: 400px) {
.container {
grid-template-columns: 1fr;
grid-template-rows: 1fr
grid-template-areas:
"nav"
"sidebar"
"main"
"content1"
"content2"
"content3"
"content4"
"content5"
"footer";
}
}
background-color: #ffffff;
margin-right: auto;
margin-left: auto;
padding: 6px;
border-top-left-radius: 15px;
border-top-right-radius: 15px;
box-shadow: 1px 6px 13px 4px rgba(0, 0, 0, 0.5);
/* h-offset v-offset blur spread */
}
nav {
grid-area: nav;
background-color: #6699FF;
border-top-left-radius: 15px;
border-top-right-radius: 15px;
}
main {
background: #84ffff;
grid-area: main;
}
#sidebar {
background: #F4A460;
grid-area: sidebar;
}
#content1 {
background: #6fffd2;
grid-area: content1;
}
#content2 {
background: #64ffda;
grid-area: content2;
}
#content3 {
background: #73ffba;
grid-area: content3;
}
#content4 {
background: #0099ff;
grid-area: content3;
}
#content5 {
background: #8080ff;
grid-area: content3;
}
footer {
grid-area: footer;
background-color: #00b9b9;
}
h1 { font-family: open sans;
color: black;
font-size: 250%;
margin: 0px;
padding-top: 7px;
padding-right: 15px;
padding-bottom: 0px;
padding-left: 15px;
}
h3 { font-family: open sans;
color: black;
font-size: 150%;
margin: 0px;
padding-top: 7px;
padding-right: 15px;
padding-bottom: 15px;
padding-left: 15px;
}
p {
font-family: 'trebuchet ms', 'Open Sans', sans-serif;
font-size: 110%;
line-height: 1.6em;
font-weight: normal;
color: black;
margin: 0px;
padding-top: 15px;
padding-right: 15px;
padding-bottom: 15px;
padding-left: 15px;
}
</style>
</head>
<body>
<div class="container">
<nav><h3>Navbar</h3></nav>
<main><h1>Main Content</h1>
<p>Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it </p>
<p>Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it </p>
<p>Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it </p>
</main>
<div id="sidebar"><h3>Sidebar</h3></div>
<div id="content1"><h3>Content1</h3></div>
<div id="content2"><h3>Content2</h3></div>
<div id="content3"><h3>Content3</h3>
<p>Lorem Ipsum is simply dummy text of the printing and typesetting industry. </p>
<div id="content4"><h3>Content4</h3>
<p>The text escapes the divs instead wrapping around to the ntex line. </p></div>
<div id="content5"><h3>Content5</h3>
<p>The text escapes the divs instead wrapping around to the ntex line. Lorem Ipsum is simply dummy text of the printing and typesetting industry.</p></div>
</div>
<footer><h3>Footer</h3></footer>
</div>
</body>
</html>
