Stopping CSS Grid column from overflowing - html

I tried stopping the column overflow with max-height, max-width, but it doesn't seem to work.
I've made three columns with CSS Grid. One for the nav section, one for the left column and one for the right column. the left column section keeps overflowing over the nav section and the right column section as shown in the screenshots.
What I'm trying to achieve:
What happens:
#import url("https://fonts.googleapis.com/css2?family=Asap:wght#400;700&display=swap");
* {
padding: 0;
margin: 0;
height: 100%;
width: 100%;
background-color: #4a6163;
font-family: "Asap";
-webkit-box-sizing: border-box;
box-sizing: border-box;
}
.main_grid {
display: -ms-grid;
display: grid;
-ms-grid-columns: 0.25fr (1fr)[2];
grid-template-columns: 0.25fr repeat(2, 1fr);
-ms-grid-rows: 1fr;
grid-template-rows: 1fr;
grid-column-gap: 0px;
grid-row-gap: 0px;
max-height: 100%;
max-width: 100%;
}
.nav_section {
-ms-grid-row: 1;
-ms-grid-column: 1;
-ms-grid-column-span: 1;
grid-area: 1 / 1 / 1 / 2;
border: 3px yellow solid;
}
.left_column {
-ms-grid-row: 1;
-ms-grid-column: 2;
-ms-grid-column-span: 1;
grid-area: 1 / 2 / 1 / 3;
border: 1px yellow solid;
}
.right_colomn {
-ms-grid-row: 1;
-ms-grid-column: 3;
-ms-grid-column-span: 1;
grid-area: 1 / 3 / 1 / 4;
border: 2px blue solid;
}
.left_column > h1 {
font-family: "Asap";
color: #f9faf4;
font-size: 13rem;
font-style: normal;
font-weight: normal;
line-height: 15.75rem;
text-transform: uppercase;
-webkit-transform: rotate(-90deg);
transform: rotate(-90deg);
display: -webkit-box;
display: -ms-flexbox;
display: flex;
border: red 3px solid;
-o-object-fit: contain;
object-fit: contain;
max-width: 100%;
max-height: 100%;
}
.main_bio {
color: #f2c4ce;
font-size: 1.75rem;
text-decoration: underline;
}
<main>
<div class="main_grid">
<div class="nav_section">
<nav class="main_nav">
home
work
contact
</nav>
</div>
<div class="left_column">
<h1 class="main_title">Hello, I'm Jack</h1>
</div>
<div class="right_colomn">
<p class="main_bio">A 20 YEAR OLD FROM A SMALL TOWN NEAR AMSTERDAM. CURRENTLY STUDYING COMPUTER SCIENCE IN LEIDEN.</p>
</div>
</div>
</main>

To avoid overflowing, you can use the rule white-space: nowrap; for your h1.
However, that will avoid breaking the line after "Hello," as well.
So I would also recommend adding a <br /> after the Hello, for explicitly breaking that line.
That should solve your line-break issues, but I noticed you're also rotating the text by 90deg, and that can mess up the heading fitting inside the cell.
So I recommend adding the rule writing-mode: tb-rl (link) to make the text be written vertically, and then rotating it 180deg instead of 90 (so it becomes bottom-up instead of top-down)
This is your snippet with the suggested changes
#import url("https://fonts.googleapis.com/css2?family=Asap:wght#400;700&display=swap");
* {
padding: 0;
margin: 0;
height: 100%;
width: 100%;
background-color: #4a6163;
font-family: "Asap";
-webkit-box-sizing: border-box;
box-sizing: border-box;
}
.main_grid {
display: -ms-grid;
display: grid;
-ms-grid-columns: 0.25fr (1fr)[2];
grid-template-columns: 0.25fr repeat(2, 1fr);
-ms-grid-rows: 1fr;
grid-template-rows: 1fr;
grid-column-gap: 0px;
grid-row-gap: 0px;
max-height: 100%;
max-width: 100%;
}
.nav_section {
-ms-grid-row: 1;
-ms-grid-column: 1;
-ms-grid-column-span: 1;
grid-area: 1 / 1 / 1 / 2;
border: 3px yellow solid;
}
.left_column {
-ms-grid-row: 1;
-ms-grid-column: 2;
-ms-grid-column-span: 1;
grid-area: 1 / 2 / 1 / 3;
border: 1px yellow solid;
}
.right_colomn {
-ms-grid-row: 1;
-ms-grid-column: 3;
-ms-grid-column-span: 1;
grid-area: 1 / 3 / 1 / 4;
border: 2px blue solid;
}
.left_column > h1 {
font-family: "Asap";
color: #f9faf4;
font-size: 13rem;
font-style: normal;
font-weight: normal;
line-height: 15.75rem;
text-transform: uppercase;
/* Updated the following 3 lines */
white-space: nowrap;
writing-mode: tb-rl;
-webkit-transform: rotate(-180deg);
transform: rotate(-180deg);
display: -webkit-box;
display: -ms-flexbox;
display: flex;
border: red 3px solid;
-o-object-fit: contain;
object-fit: contain;
max-width: 100%;
max-height: 100%;
}
.main_bio {
color: #f2c4ce;
font-size: 1.75rem;
text-decoration: underline;
}
<main>
<div class="main_grid">
<div class="nav_section">
<nav class="main_nav">
home
work
contact
</nav>
</div>
<div class="left_column">
<h1 class="main_title">Hello,<br/>I'm Jack</h1>
</div>
<div class="right_colomn">
<p class="main_bio">A 20 YEAR OLD FROM A SMALL TOWN NEAR AMSTERDAM. CURRENTLY STUDYING COMPUTER SCIENCE IN LEIDEN.</p>
</div>
</div>
</main>

Related

nav links get separated each in a new row with css-grid

I'm trying to get the three links together above each other and center them in the middle of the page. (Like on the screenshot).
I have tried things like grid-row: 1; but doesn't seem to work. Seems like they get separated on a new row, but there is only 1 row with the full height of the page.
This is a pic of what I'm trying to achieve:
this is a picture of the problem:
#import url("https://fonts.googleapis.com/css2?family=Asap:wght#400;700&display=swap");
* {
padding: 0;
margin: 0;
height: 100%;
width: 100%;
background-color: #4a6163;
font-family: "Asap";
-webkit-box-sizing: border-box;
box-sizing: border-box;
}
.main_grid {
display: -ms-grid;
display: grid;
-ms-grid-columns: 0.15fr 0.5fr (1fr)[1];
grid-template-columns: 0.15fr 0.5fr repeat(1, 1fr);
-ms-grid-rows: 1fr;
grid-template-rows: 1fr;
grid-column-gap: 0px;
grid-row-gap: 0px;
max-height: 100%;
max-width: 100%;
}
.nav_section {
-ms-grid-row: 1;
-ms-grid-column: 1;
-ms-grid-column-span: 1;
grid-area: 1 / 1 / 1 / 2;
grid-row-start: 1;
}
.left_column {
-ms-grid-row: 1;
-ms-grid-column: 2;
-ms-grid-column-span: 1;
grid-area: 1 / 2 / 1 / 3;
}
.right_colomn {
-ms-grid-row: 1;
-ms-grid-column: 3;
-ms-grid-column-span: 1;
grid-area: 1 / 3 / 1 / 4;
}
.left_column > h1 {
font-family: "Asap";
color: #f9faf4;
font-size: 13.75rem;
font-style: normal;
font-weight: normal;
line-height: 15.75rem;
text-transform: uppercase;
-webkit-writing-mode: tb-rl;
-ms-writing-mode: tb-rl;
writing-mode: tb-rl;
-webkit-transform: rotate(-180deg);
transform: rotate(-180deg);
display: -webkit-box;
display: -ms-flexbox;
display: flex;
max-width: 100%;
max-height: 100%;
padding: 3rem;
}
.main_bio {
color: #f2c4ce;
font-size: 2.75rem;
text-decoration: underline;
display: -webkit-box;
display: -ms-flexbox;
display: flex;
-webkit-box-orient: vertical;
-webkit-box-direction: reverse;
-ms-flex-direction: column-reverse;
flex-direction: column-reverse;
padding: 6rem;
}
.nav_section {
max-width: 100%;
max-height: 100%;
border: blue 4px solid;
-ms-grid-row: 1;
grid-row: 1;
display: -ms-grid;
display: grid;
}
.main_nav {
display: block;
}
.main_nav > a {
text-decoration: none;
color: #f2c4ce;
text-transform: uppercase;
color: #f2c4ce;
display: -webkit-box;
display: -ms-flexbox;
display: flex;
-webkit-box-orient: vertical;
-webkit-box-direction: normal;
-ms-flex-direction: column;
flex-direction: column;
-webkit-box-pack: center;
-ms-flex-pack: center;
justify-content: center;
-webkit-box-align: center;
-ms-flex-align: center;
align-items: center;
}
.main_nav > a {
color: #f2c4ce;
}
.social_nav > a {
text-transform: uppercase;
text-decoration: none;
color: #f2c4ce;
}
<main>
<div class="main_grid">
<div class="nav_section">
<nav class="main_nav" aria-label="main_navigation">
home
work
contact
</nav>
<nav class="social_nav" aria-label="social_navigation">
github
linkedin
</nav>
</div>
<div class="left_column">
<h1 class="main_title">Hello,<br> I'm Jack</h1>
</div>
<div class="right_colomn">
<p class="main_bio">A 20 YEAR OLD FROM A SMALL TOWN NEAR AMSTERDAM. CURRENTLY STUDYING COMPUTER SCIENCE IN LEIDEN.</p>
</div>
</div>
</main>
i tried adding this css, and it seems to work :)
first put in the end this
.main_nav,
.social_nav {
display: grid;
place-content: center;
}
delete this
and deleting in your .main_nav>a selector this:
display: flex;
flex-direction: column;
justify-content: center;
align-items: center;
or change to this
and in the end, it will be:
.main_nav>a {
text-decoration: none;
color: #f2c4ce;
text-transform: uppercase;
align-items: center;
}
Here The Runnable Code on JFFIDLE :)
#import url("https://fonts.googleapis.com/css2?family=Asap:wght#400;700&display=swap");
* {
padding: 0;
margin: 0;
height: 100%;
width: 100%;
background-color: #4a6163;
font-family: "Asap";
box-sizing: border-box;
}
.main_grid {
display: grid;
grid-template-columns: 0.15fr 0.5fr repeat(1, 1fr);
grid-template-rows: 1fr;
grid-column-gap: 0px;
grid-row-gap: 0px;
max-height: 100%;
max-width: 100%;
}
.nav_section {
grid-area: 1 / 1 / 1 / 2;
grid-row-start: 1;
}
.left_column {
-ms-grid-column-span: 1;
grid-area: 1 / 2 / 1 / 3;
}
.right_colomn {
-ms-grid-column-span: 1;
grid-area: 1 / 3 / 1 / 4;
}
.left_column>h1 {
font-family: "Asap";
color: #f9faf4;
font-size: 13.75rem;
font-style: normal;
font-weight: normal;
line-height: 15.75rem;
text-transform: uppercase;
writing-mode: tb-rl;
transform: rotate(-180deg);
display: flex;
max-width: 100%;
max-height: 100%;
padding: 3rem;
}
.main_bio {
color: #f2c4ce;
font-size: 2.75rem;
text-decoration: underline;
display: flex;
flex-direction: column-reverse;
padding: 6rem;
}
.nav_section {
max-width: 100%;
max-height: 100%;
border: blue 4px solid;
grid-row: 1;
display: grid;
}
.main_nav {
display: block;
}
.main_nav>a {
text-decoration: none;
color: #f2c4ce;
text-transform: uppercase;
color: #f2c4ce;
}
.main_nav>a {
color: #f2c4ce;
}
.social_nav>a {
text-transform: uppercase;
text-decoration: none;
color: #f2c4ce;
}
.main_nav,
.social_nav {
display: grid;
place-content: center;
}
.main_nav>a {
text-decoration: none;
color: #f2c4ce;
text-transform: uppercase;
align-items: center;
}
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<link rel="stylesheet" href="style.css">
</head>
<body>
<main>
<div class="main_grid">
<div class="nav_section">
<nav class="main_nav" aria-label="main_navigation">
home
work
contact
</nav>
<nav class="social_nav" aria-label="social_navigation">
github
linkedin
</nav>
</div>
<div class="left_column">
<h1 class="main_title">Hello,<br> I'm Jack</h1>
</div>
<div class="right_colomn">
<p class="main_bio">A 20 YEAR OLD FROM A SMALL TOWN NEAR AMSTERDAM. CURRENTLY STUDYING COMPUTER SCIENCE IN LEIDEN.</p>
</div>
</div>
</main>
</body>
</html>
is this help you, please upvote this to help more people !

How to overlay circle and semi-circle elements using css-grid for resposive design

I'm new to css and I have a specific question about overlaying using css grid.
What I am trying to achieve is having 5 circles overlaying each other. These five circles comprise two boxes on each side of a fifth circle made out of two semi-circles. I want each circle(Or semicircle) to be a different colour/object.
I want it to be responsive, so I have used a grid system.
This has caused less problems then when I attempted to resolve the problem using flex, but it still doesn't work as I need.
Here is the image of what I want to create:
Currently, the circles in the left box work perfectly, but in the right box the first element (black semi-circle) doesn't start in the left side of the box and I don't know why.
I had to use the margin property to "stick" it to the left side of the box. But then it doesn't work as responsively as I want and as it works in the left box.
Can anyone tell me please where is the problem?
Thank you
EDIT
I should have been clearer.
All elements in the right (white) box aren't working properly. Beside the problem with black semi-circle, the green circles are overflowing the parent div, when screen size is smaller.
I'm trying to figure out, why these elements don't behave same as the elements in the left box. And how to fix it.
Here is the code (without using the margin property):
html {
font-family: 'Titillium Web', sans-serif;
font-size: 20px;
}
:root {
--yellowgreen: #ECF22E;
--applegreen: #BCDD15;
--brightgreen: #f4ff96;
}
/*||Circles -----------------------------*/
.container {
display: flex;
}
.circle {
display: flex;
align-items: center;
justify-content: center;
flex-direction: column;
flex-wrap: wrap;
border-radius: 50%;
}
.circle p {
margin: 0;
}
.circle span {
font-size: 1rem;
font-weight: normal;
}
.semi-circle {
display: flex;
align-items: center;
justify-content: center;
flex-direction: column;
align-items: center;
justify-content: center;
}
.semi-circle p {
margin: 0;
}
.semi-circle span {
font-size: 1rem;
font-weight: normal;
}
#dark-box {
display: grid;
grid-template: repeat(4, 1fr) / repeat(5, 1fr);
width: 40rem;
border-top: 2px solid var(--applegreen);
border-bottom: 2px solid var(--applegreen);
background-color: black;
}
#bright-box {
display: grid;
grid-template: repeat(4, 1fr) / repeat(5, 1fr);
width: 40rem;
border-top: 2px solid var(--applegreen);
border-bottom: 2px solid var(--applegreen);
background-color: white;
}
.section-introduction .circle {
text-align: center;
height: 16rem;
width: 16rem;
font-size: 1.3rem;
font-weight: 700;
text-transform: capitalize;
}
.brightgreen-circle {
grid-row: 2 / span 2;
grid-column: 1 / span 2;
background-color: var(--brightgreen);
}
.yellowgreen-circle {
grid-row: 2 / span 2;
grid-column: 3 / span 2;
background-color: var(--yellowgreen);
}
.left-semi-circle {
border-radius: 16rem 0 0 16rem;
height: 16rem;
width: 8rem;
grid-row: 2 / span 2;
grid-column: 5 / span 1;
background-color: white;
font-size: 1.3rem;
font-weight: 700;
text-align: center;
}
.right-semi-circle {
border-radius: 0 16rem 16rem 0;
height: 16rem;
width: 8rem;
color: white;
grid-row: 2 / 4;
grid-column: 1 / span 2;
z-index: 10;
background-color: black;
font-size: 1.3rem;
font-weight: 700;
text-align: center;
}
.applegreen-circle {
grid-row: 2 / 4;
grid-column: 2 / span 2;
z-index: 2;
background-color: var(--applegreen);
}
.brightgreen-circle2 {
grid-row: 2 / 4;
grid-column: 4 / span 2;
background-color: var(--brightgreen);
}
<section class="section-introduction">
<h2 class="section-heading">Color pallete</h2>
<div class="container">
<div id="dark-box">
<div class="brightgreen-circle circle ">
<p>brightgreen</p>
<span>#F4FF96</span>
</div>
<div class="yellowgreen-circle circle">
<p>yellowgreen</p>
<span>#ECF22E</span>
</div>
<div class="left-semi-circle semi-circle">
<p>White</p>
<span>#FFFFFF</span>
</div>
</div>
<div id="bright-box">
<div class="right-semi-circle semi-circle">
<p>Black</p>
<span>#000000</span>
</p>
</div>
<div class="applegreen-circle circle">
<p>applegreen</p>
<span>#BCDD15</span>
</div>
<div class="brightgreen-circle2 circle">
<p>brightgreen</p>
<span>#F4FF96</span>
</div>
</div>
</div>
</div>
</section>
you can use a gradient for the background and a single container where you can set within your circle.
If you use 4 columns for each circle, the forth can be used for the overlapping. If that is too much, try use 5 or 6 columns.
here is the example of the idea:
html {
font-family: "Titillium Web", sans-serif;
font-size: clamp(10px, 1.5vw, 30px);
}
:root {
--yellowgreen: #ecf22e;
--applegreen: #bcdd15;
--brightgreen: #f4ff96;
}
/*||Circles -----------------------------*/
.container {
display:grid;
align-items:center;
height:30rem;
width:max-content;
margin:auto;
background:linear-gradient(to right,black 50%, white 50%);
border-top: 2px solid var(--applegreen);
border-bottom: 2px solid var(--applegreen);
}
.brightgreen-circle {
grid-row:1;
grid-column: 1 / span 4;
}
.yellowgreen-circle {
grid-row: 1;
grid-column: 4 / span 4;
}
.left-semi-circle {
grid-row: 1;
grid-column: 7 / span 2;
}
.right-semi-circle {
grid-row: 1;
grid-column: 9 / span 2;
z-index: 10;
}
.applegreen-circle {
grid-row:1;
grid-column: 10 / span 4;
}
.brightgreen-circle2 {
grid-row: 1;
grid-column: 13 / span 4;
}
.circle {
display: flex;
align-items: center;
justify-content: center;
flex-direction: column;
flex-wrap: wrap;
border-radius: 50%;
}
.circle p {
margin: 0;
}
.circle span {
font-size: 1rem;
font-weight: normal;
}
.semi-circle {
display: flex;
align-items: center;
justify-content: center;
flex-direction: column;
align-items: center;
justify-content: center;
}
.semi-circle p {
margin: 0;
}
.semi-circle span {
font-size: 1rem;
font-weight: normal;
}
.section-introduction .circle {
text-align: center;
height: 16rem;
width: 16rem;
font-size: 1.3rem;
font-weight: 700;
text-transform: capitalize;
}
.brightgreen-circle {
background-color: var(--brightgreen);
}
.yellowgreen-circle {
background-color: var(--yellowgreen);
}
.left-semi-circle {
border-radius: 16rem 0 0 16rem;
height: 16rem;
width: 8rem;
background-color: white;
font-size: 1.3rem;
font-weight: 700;
text-align: center;
}
.right-semi-circle {
border-radius: 0 16rem 16rem 0;
height: 16rem;
width: 8rem;
color: white;
z-index: 10;
background-color: black;
font-size: 1.3rem;
font-weight: 700;
text-align: center;
}
.applegreen-circle {
z-index: 2;
background-color: var(--applegreen);
}
.brightgreen-circle2 {
background-color: var(--brightgreen);
}
<section class="section-introduction">
<h2 class="section-heading">Color pallete</h2>
<div class="container">
<div class="brightgreen-circle circle ">
<p>brightgreen</p><span>#F4FF96</span>
</div>
<div class="yellowgreen-circle circle">
<p>yellowgreen</p><span>#ECF22E</span>
</div>
<div class="left-semi-circle semi-circle">
<p>White</p><span>#FFFFFF</span>
</div>
<div class="right-semi-circle semi-circle">
<p>Black</p><span>#000000</span></p>
</div>
<div class="applegreen-circle circle">
<p>applegreen</p><span>#BCDD15</span>
</div>
<div class="brightgreen-circle2 circle">
<p>brightgreen</p><span>#F4FF96</span>
</div>
</section>
note the demo sets font-size with font-size: clamp(10px, 1.5vw, 30px); so you can see it rescale if open the snippet in fullpage.

CSS grid item cell expands instead of overflowing

I have a css grid:
|-------|-------------------|
|-------| |
| | overflow |
|-------|-------------------|
|-------|-------------------|
And I cannot stop the "overflow" from growing, basically it always expands, despite having set:
overflow: auto;
in the css. How can achieve this?
The snippet below.
html {
font-size: 22px;
}
body {
padding: 1rem;
/* grid-template-columns: 1fr 3fr; */
}
.wrapper {
max-height: 70vh;
padding: 1rem;
}
.header {
background-color: red;
color: white;
padding: 1rem;
height: 2rem;
resize: horizontal;
grid-area: 1 / 1 / 2 / 2;
}
.nav {
background-color: lightgrey;
color: baclk;
padding: 1rem;
height: 4rem;
overflow: auto;
min-width: 12rem;
resize: horizontal;
grid-area: 2 / 1 / 3 / 2;
}
.scroll {
background-color: dodgerblue;
color: white;
padding: 1rem;
overflow: auto;
grid-area: 1 / 2 / 3 / 3;
}
.prev {
background-color: black;
color: white;
padding: 1rem;
height: 4rem;
grid: 3 / 1 / 4 / 2;
}
.select {
background-color: lightgrey;
color: white;
padding: 1rem;
height: 4rem;
grid-area: 4 2 4 4;
}
.cards {
max-width: 1200px;
margin: 0 auto;
display: grid;
grid-gap: 0.5rem;
}
/* Screen larger than 600px? 2 column */
#media (min-width: 600px) {
.cards {
grid-template-columns: 1fr 3fr;
}
}
<div class="wrapper">
<div class="cards">
<div class="header">HEADER</div>
<div class="scroll">
<p>111</p>
<p>222</p>
<p>333</p>
<p>444</p>
<p>555</p>
<!-- <p>666</p>
<p>777</p>
<p>888</p>
<p>999</p> -->
</div>
<div class="nav">NAV</div>
<div class="prev">PREVIEW</div>
<div class="select">SELECT</div>
</div>
</div>
It turned out the solution is to add one line to the grid definition:
grid-template-rows: auto 1fr auto;
This produces a nice layout, when the "scroll" area overflows, while the grid scales as expected. Updated snippet below.
html {
font-size: 22px;
}
body {
padding: 1rem;
overflow: hidden;
/* grid-template-columns: 1fr 3fr; */
}
.header {
background-color: red;
color: white;
padding: 1rem;
height: 2rem;
grid-area: 1 / 1 / 2 / 2;
}
.nav {
background-color: lightgrey;
color: baclk;
padding: 1rem;
height: auto;
overflow: auto;
min-width: 12rem;
resize: horizontal;
grid-area: 2 / 1 / 3 / 2;
}
.scroll {
background-color: dodgerblue;
color: white;
padding: 1rem;
overflow: auto;
max-height: 70vh;
grid-area: 1 / 2 / 3 / 3;
}
.prev {
background-color: black;
color: white;
padding: 1rem;
max-height: 30vh;
grid: 3 / 1 / 4 / 2;
}
.select {
background-color: lightgrey;
color: white;
padding: 1rem;
height: 4rem;
grid-area: 4 2 4 4;
}
.cards {
max-width: 80vw;
height: 90vh;
margin: 0 auto;
display: grid;
grid-gap: 0.5rem;
}
/* Screen larger than 600px? 2 column */
#media (min-width: 600px) {
.cards {
grid-template-columns: 1fr 3fr;
grid-template-rows: auto 1fr auto;
}
}
<div class="wrapper">
<div class="cards">
<div class="header">HEADER</div>
<div class="scroll">
<p>111</p>
<p>222</p>
<p>333</p>
<p>444</p>
<p>555</p>
<p>666</p>
<p>777</p>
<!-- <p>888</p>
<p>999</p> -->
</div>
<div class="nav">NAV</div>
<div class="prev">PREVIEW</div>
<div class="select">SELECT</div>
</div>
</div>

CSS image pushing grid item down

So I've been trying to put an image inside a grid but its causing me problems.
Right now, my biggest issue is that is pushing another grid item down.
body {
padding: 0;
margin: 0;
}
.main {
width: 100%;
height: 100vh;
margin: 0;
padding: 0;
display: grid;
grid-template: repeat(20, 1fr) / repeat(20, 1fr);
}
.main-bar {
grid-row: 1/16;
grid-column: 4/21;
display: grid;
grid-template: repeat(20, 1fr) / repeat(20, 1fr);
}
.main-info {
grid-column: 1/21;
grid-row: 1/21;
background: #333;
display: grid;
grid-template: repeat(20, 1fr) / repeat(20, 1fr);
}
.header-title {
grid-column: 3;
grid-row: 2/8;
background: #000;
}
.business {
grid-column: 17;
}
.side-bar {
background: #fff;
grid-row: 1/21;
grid-column: 1/4;
display: grid;
grid-template-rows: repeat(10, 1fr);
border-right: 1px solid #0F6B99;
}
.side-bar img {
width: 100%;
height: auto;
display: block;
margin-left: auto;
margin-right: auto;
margin-top: -24px;
}
.home-button {
padding: 20px;
text-align: center;
background: #0F6B99;
grid-row: 3/4;
}
.buy-button {
padding: 20px;
text-align: center;
background: #59B3B3;
grid-row: 4/5;
}
.sell-button {
padding: 20px;
text-align: center;
background: #8FCCB8;
grid-row: 5/6;
}
.rent-button {
padding: 20px;
text-align: center;
background: #B8E6B8;
grid-row: 6/7;
}
.article1 {
background: #e6174b;
grid-row: 16/21;
grid-column: 4/11;
}
.article2 {
background: #8FCCB8;
grid-row: 16/21;
grid-column: 11/18;
}
.article3 {
background: #B8E6B8;
grid-row: 16/21;
grid-column: 18/21;
}
<div class="main">
<div class="main-bar">
<div class="main-info">
<img class="business" src="http://pngimg.com/uploads/businessman/businessman_PNG6564.png" alt="">
<div class="header-title">High Quality Realstate Asistance</div>
</div>
</div>
<div class="side-bar">
<!--<img src="img/logo.png" alt="">-->
<div class="home-button">
Home
</div>
<div class="buy-button">
Buy
</div>
<div class="sell-button">
Sell
</div>
<div class="rent-button">
Rent
</div>
</div>
<div class="article1">
</div>
<div class="article2">
</div>
<div class="article3">
</div>
</div>
The image in question has a class as business and the item is pushing down has a class as header-title. Header-title should be inside main-info, but when 'business' appears, it pushes header-title down!
!
The issue here is that your image with the business class is overflowing its own grid and the grid of its container.
In order to resolve this add the property overflow: hidden to both the .main-info class and the .business class.
These classes also need the "display: grid" property so the browser can process the grid-column and grid-row property accordingly for those two classes.
Once those additions are made you can tweak the grid-row and grid-column for the the .business class and the .header-title classes accordingly to find your desired positions.
Full CSS and HTML Below:
body {
padding: 0;
margin: 0;
}
.main {
width: 100%;
height: 100vh;
margin: 0;
padding: 0;
display: grid;
grid-template: repeat(20, 1fr) / repeat(20, 1fr);
}
.main-bar {
grid-row: 1/16;
grid-column: 4/21;
display: grid;
grid-template: repeat(20, 1fr) / repeat(20, 1fr);
}
.main-info {
grid-column: 1/21;
grid-row: 1/21;
background: #333;
display: grid;
grid-template: repeat(20, 1fr) / repeat(20, 1fr);
overflow: hidden;
}
.header-title {
grid-column: 3;
grid-row: 2/8;
background: #000;
display: grid;
}
.business {
grid-column: 17;
overflow: hidden;
display: grid;
}
.side-bar {
background: #fff;
grid-row: 1/21;
grid-column: 1/4;
display: grid;
grid-template-rows: repeat(10, 1fr);
border-right: 1px solid #0F6B99;
}
.side-bar img {
width: 100%;
height: auto;
display: block;
margin-left: auto;
margin-right: auto;
margin-top: -24px;
}
.home-button {
padding: 20px;
text-align: center;
background: #0F6B99;
grid-row: 3/4;
}
.buy-button {
padding: 20px;
text-align: center;
background: #59B3B3;
grid-row: 4/5;
}
.sell-button {
padding: 20px;
text-align: center;
background: #8FCCB8;
grid-row: 5/6;
}
.rent-button {
padding: 20px;
text-align: center;
background: #B8E6B8;
grid-row: 6/7;
}
.article1 {
background: #e6174b;
grid-row: 16/21;
grid-column: 4/11;
}
.article2 {
background: #8FCCB8;
grid-row: 16/21;
grid-column: 11/18;
}
.article3 {
background: #B8E6B8;
grid-row: 16/21;
grid-column: 18/21;
}
<div class="main">
<div class="main-bar">
<div class="main-info">
<img class="business" src="http://pngimg.com/uploads/businessman/businessman_PNG6564.png" alt="">
<div class="header-title">High Quality Realstate Asistance</div>
</div>
</div>
<div class="side-bar">
<!--<img src="img/logo.png" alt="">-->
<div class="home-button">
Home
</div>
<div class="buy-button">
Buy
</div>
<div class="sell-button">
Sell
</div>
<div class="rent-button">
Rent
</div>
</div>
<div class="article1">
</div>
<div class="article2">
</div>
<div class="article3">
</div>
</div>

Grid item won't take full height of parent container

I am trying to create three items inside of a nested grid item. As you can see from the code, I've put the 'panels' div in-between the 'jumbo' and 'content' divs. I also nested three divs inside. In the CSS, I added a nested grid inside of .panels.
I want the 'panels' div to be split in three equally size parts on the vertical axis. Imagine three square blocks stack one after another. But the nested items don't fill the entire 'panels' div. If you run the code snippet, you can see that the panels are nested but don't take up the entire space. They take up a small percentage of their parent. I added background-color: white !important to one of the nested panels to show how small it is.
Another example can be seen here: https://codepen.io/rachelandrew/pen/NqQPBR/
But again, the nested E, F and G items don't expand to fill up the entire D section.
Is there a way to make the three panels fill in their parent?
.container {
display: grid;
width: 100%;
height: 100%;
grid-gap: 3px;
grid-template-columns: repeat(10, 1fr);
grid-template-rows: 40px 130px 130px 130px 60px 330px 40px;
}
.header {
grid-column: 1 / -1;
}
.jumbo {
grid-column: 1 / -1;
grid-row: 2 / 5;
}
.panels {
grid-column: 3 / 9;
grid-row: 4 / 6;
z-index: 1;
display: grid;
grid-template-columns: repeat(3, 1fr);
}
.panel1 {
grid-row: 1 / 2;
grid-row: 1;
background-color: white !important;
z-index: 2;
}
.content {
grid-column: 1 / -1;
grid-row: 5 / 7;
}
.footer {
grid-column: 1 / -1;
}
/* Styling */
.container > div {
display: grid;
justify-content: center;
align-items: center;
font-size: 2em;
color: #ffeead;
}
html, body {
background-color: #ffeead;
box-sizing: border-box;
height: 100%;
margin: 0px;
font-family: "Work Sans"
}
.container > div:nth-child(1n) {
background-color: #96ceb4;
}
.container > div:nth-child(3n) {
background-color: #88d8b0;
}
.container > div:nth-child(2n) {
background-color: #ff6f69;
}
.container > div:nth-child(4n) {
background-color: #ffcc5c;
}
.panels > div:nth-child(1n) {
background-color: #96ceb4;
}
<div class="container">
<div class="header">
HEADER
</div>
<div class="jumbo">
JUMBO
</div>
<div class="panels">
<div class="panel1">PANEL1</div>
<div class="panel2">PANEL2</div>
<div class="panel3">PANEL3</div>
</div>
<div class="content">
CONTENT
</div>
<div class="footer">
FOOTER
</div>
</div>
You have align-items: center applied to the nested grid container (.panels).
With that rule, you override the default align-items: stretch, which would set your grid items to the full height of the parent. Instead, you have the items vertically centered.
So they can be full height, remove align-items: center from the .panels element:
.container > div:not(.panels) {
align-items: center;
}
.container {
display: grid;
width: 100%;
height: 100%;
grid-gap: 3px;
grid-template-columns: repeat(10, 1fr);
grid-template-rows: 40px 130px 130px 130px 60px 330px 40px;
}
.header {
grid-column: 1 / -1;
}
.jumbo {
grid-column: 1 / -1;
grid-row: 2 / 5;
}
.panels {
grid-column: 3 / 9;
grid-row: 4 / 6;
z-index: 1;
display: grid;
grid-template-columns: repeat(3, 1fr);
}
.panel1 {
grid-row: 1 / 2;
grid-row: 1;
background-color: white !important;
z-index: 2;
}
.content {
grid-column: 1 / -1;
grid-row: 5 / 7;
}
.footer {
grid-column: 1 / -1;
}
/* Styling */
.container > div {
display: grid;
justify-content: center;
/* align-items: center; */
font-size: 2em;
color: #ffeead;
}
/* new */
.container > div:not(.panels) {
align-items: center;
}
html, body {
background-color: #ffeead;
box-sizing: border-box;
height: 100%;
margin: 0px;
font-family: "Work Sans"
}
.container > div:nth-child(1n) { background-color: #96ceb4; }
.container > div:nth-child(3n) { background-color: #88d8b0; }
.container > div:nth-child(2n) { background-color: #ff6f69; }
.container > div:nth-child(4n) { background-color: #ffcc5c; }
.panels > div:nth-child(1n) { background-color: #96ceb4; }
<div class="container">
<div class="header">HEADER</div>
<div class="jumbo">JUMBO</div>
<div class="panels">
<div class="panel1">PANEL1</div>
<div class="panel2">PANEL2</div>
<div class="panel3">PANEL3</div>
</div>
<div class="content">CONTENT</div>
<div class="footer">FOOTER</div>
</div>
Then, to vertically center the content of .panels, I would target the content directly:
.panels > div {
display: flex;
align-items: center;
}
.container {
display: grid;
width: 100%;
height: 100%;
grid-gap: 3px;
grid-template-columns: repeat(10, 1fr);
grid-template-rows: 40px 130px 130px 130px 60px 330px 40px;
}
.header {
grid-column: 1 / -1;
}
.jumbo {
grid-column: 1 / -1;
grid-row: 2 / 5;
}
.panels {
grid-column: 3 / 9;
grid-row: 4 / 6;
z-index: 1;
display: grid;
grid-template-columns: repeat(3, 1fr);
}
.panel1 {
grid-row: 1 / 2;
grid-row: 1;
background-color: white !important;
z-index: 2;
}
.content {
grid-column: 1 / -1;
grid-row: 5 / 7;
}
.footer {
grid-column: 1 / -1;
}
/* Styling */
.container > div {
display: grid;
justify-content: center;
/* align-items: center; */
font-size: 2em;
color: #ffeead;
}
/* new */
.container > div:not(.panels) {
align-items: center;
}
/* new */
.panels > div {
display: flex;
align-items: center;
}
html, body {
background-color: #ffeead;
box-sizing: border-box;
height: 100%;
margin: 0px;
font-family: "Work Sans"
}
.container > div:nth-child(1n) { background-color: #96ceb4; }
.container > div:nth-child(3n) { background-color: #88d8b0; }
.container > div:nth-child(2n) { background-color: #ff6f69; }
.container > div:nth-child(4n) { background-color: #ffcc5c; }
.panels > div:nth-child(1n) { background-color: #96ceb4; }
<div class="container">
<div class="header">HEADER</div>
<div class="jumbo">JUMBO</div>
<div class="panels">
<div class="panel1">PANEL1</div>
<div class="panel2">PANEL2</div>
<div class="panel3">PANEL3</div>
</div>
<div class="content">CONTENT</div>
<div class="footer">FOOTER</div>
</div>
Keep in mind that there are three structural levels in a grid container:
the container
the item (child of the container)
the content (child of the item)
Grid properties only work between parent and child.
So when you apply grid centering properties on the container, they apply to the item, not the content. To center the content, you need to treat the item as parent and content as child.
There's a more in-depth explanation of these concepts and methods here: Centering in CSS Grid
Well, what you have done is, you created three columns inside the 'panels' div:
grid-template-columns: repeat(3, 1fr);
But you gave the children only a position for the row (twice):
grid-row: 1 / 2;
grid-row: 1;
So if you change 'columns' to 'rows' in '.panels' and clean up the code for '.panel1' it should work like a cham!
Thank you all for your suggestions. I solved the issue by removing the nested 'panel' and simply creating three different panels to fill the same space.
.container {
display: grid;
width: 100%;
height: 100%;
grid-gap: 3px;
grid-template-columns: repeat(13, 1fr);
grid-template-rows: 50px 218px 218px 200px 80px 530px 40px;
}
.header {
grid-column: 1 / -1;
position: sticky;
top: 0;
z-index: 3;
}
.jumbo {
grid-column: 1 / -1;
grid-row: 2 / 5;
}
.panel1 {
background-color: white !important;
z-index: 1;
grid-column: 3 / 6;
grid-row: 4 / 6;
}
.panel2 {
background-color: black !important;
z-index: 1;
grid-column: 6 / 9;
grid-row: 4 / 6;
}
.panel3 {
background-color: purple !important;
z-index: 2;
grid-column: 9 / 12;
grid-row: 4 / 6;
}
.content-left {
grid-column: 1 / 5;
grid-row: 5 / 7;
}
.content-right {
grid-column: 5 / -1;
grid-row: 5 / 7;
display: grid;
grid-gap: 5px;
align-items: start;
grid-template-columns: repeat(3, 1fr);
grid-template-rows: repeat(2, 1fr)
}
.content-right > div {
background-color: white;
z-index: 2;
}
.footer {
grid-column: 1 / -1;
}
.container > div {
justify-content: center;
align-items: center;
font-size: 2em;
color: #ffeead;
}
html, body {
background-color: #ffeead;
box-sizing: border-box;
height: 100%;
margin: 0px;
font-family: "Work Sans"
}
.container > div:nth-child(1n) {
background-color: #96ceb4;
}
.container > div:nth-child(3n) {
background-color: #88d8b0;
}
.container > div:nth-child(2n) {
background-color: #ff6f69;
}
.container > div:nth-child(4n) {
background-color: #ffcc5c;
}
.panels > div:nth-child(1n) {
background-color: #96ceb4;
}
<div class="container">
<div class="header">
HEADER
</div>
<div class="jumbo">
JUMBO
</div>
<div class="panel1">PANEL1</div>
<div class="panel2">PANEL2</div>
<div class="panel3">PANEL3</div>
<div class="content-left">
CONTENT-LEFT
</div>
<div class="content-right">
<div class="content-right1">1</div>
<div class="content-right2">2</div>
<div class="content-right3">3</div>
<div class="content-right4">4</div>
<div class="content-right5">5</div>
<div class="content-right6">6</div>
</div>
<div class="footer">
FOOTER
</div>
</div>