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 !
Related
Here is the JSfiddle complete code link:
CODE
my clock code output
* {
padding: 0;
margin: 0;
box-sizing: border-box;
}
body {
background: #0b172a;
font-family: sans-serif;
}
#container {
height: 100vh;
display: flex;
align-items: center;
justify-content: center;
flex-direction: column;
padding: 5rem;
color: white;
text-transform: uppercase;
}
.clock-ctr {
position: relative;
border: 2px solid white;
height: 80vh;
width: 80vw;
padding: 10px;
display: flex;
justify-content: center;
align-items: center;
}
.hour-ctr {
grid-area: hour;
}
.min-ctr {
grid-area: min;
}
.sec-ctr {
grid-area: sec;
}
.ampm {
grid-area: ampm;
background: #bc4123;
}
.time-ctr {
position: absolute;
height: 70%;
width: 90%;
display: grid;
grid-template-columns: 1fr 1fr 1fr;
grid-template-rows: auto;
gap: 10px;
grid-template-areas: "hour min sec" "ampm ampm ampm";
}
h1 {
margin-bottom: 1rem;
letter-spacing: 8px;
font-size: 2.5rem;
}
.time-box {
background: #bc4123;
border-radius: 10px;
display: grid;
justify-items: center;
align-items: center;
height: auto;
text-align: center;
font-weight: bold;
font-size: 28px;
}
<div id="container">
<h1 class="clock-title">Clock</h1>
<div class="clock-ctr">
<div class="time-ctr">
<div class="hour-ctr time-box">
<p class="hour-value">00</p>
<p class="hour-title">Hour</p>
</div>
<div class="min-ctr time-box">
<p class="min-value">00</p>
<p class="min-title">Minute</p>
</div>
<div class="sec-ctr time-box">
<p class="sec-value">00</p>
<p class="sec-title">Second</p>
</div>
<p class="ampm time-box">AM</p>
</div>
</div>
</div>
Can any one tell me how to improve this code
I tried to make is completely responsive but it is not not working,
I tired to use flex to make the element appear in center of page.
Then I use grid to create the clock layout and i didn't knew how to align the cells so I used grid again in them. I was using rem and em to make responsive code but it didn't work out well. please review my code.
This is because of the font-size of the time-box div that is not responsive (28px whatever the device size), To make it responsive I added media queries to change the font depending on the device width, As presented in this example:
* {
padding: 0;
margin: 0;
box-sizing: border-box;
}
body {
background: #0b172a;
font-family: sans-serif;
}
#container {
height: 100vh;
display: flex;
align-items: center;
justify-content: center;
flex-direction: column;
padding: 5rem;
color: white;
text-transform: uppercase;
}
.clock-ctr {
position: relative;
border: 2px solid white;
height: 80vh;
width: 80vw;
padding: 10px;
display: flex;
justify-content: center;
align-items: center;
}
.hour-ctr {
grid-area: hour;
}
.min-ctr {
grid-area: min;
}
.sec-ctr {
grid-area: sec;
}
.ampm {
grid-area: ampm;
background: #bc4123;
}
.time-ctr {
position: absolute;
height: 70%;
width: 90%;
display: grid;
grid-template-columns: 1fr 1fr 1fr;
grid-template-rows: auto;
gap: 10px;
grid-template-areas: "hour min sec" "ampm ampm ampm";
}
h1 {
margin-bottom: 1rem;
letter-spacing: 8px;
font-size: 2.5rem;
}
.time-box {
background: #bc4123;
border-radius: 10px;
display: grid;
justify-items: center;
align-items: center;
height: auto;
text-align: center;
font-weight: bold;
}
#media (min-width:768px) {
.time-box {
font-size: 18px;
}
}
#media (min-width:1024px) {
.time-box {
font-size: 22px;
}
}
#media (min-width:1280px) {
.time-box {
font-size: 28px;
}
}
<div id="container">
<h1 class="clock-title">Clock</h1>
<div class="clock-ctr">
<div class="time-ctr">
<div class="hour-ctr time-box">
<p class="hour-value">00</p>
<p class="hour-title">Hour</p>
</div>
<div class="min-ctr time-box">
<p class="min-value">00</p>
<p class="min-title">Minute</p>
</div>
<div class="sec-ctr time-box">
<p class="sec-value">00</p>
<p class="sec-title">Second</p>
</div>
<p class="ampm time-box">AM</p>
</div>
</div>
</div>
You can as well use calc() function, so you can calculate your font size relative to the screen width like this:
* {
padding: 0;
margin: 0;
box-sizing: border-box;
}
body {
background: #0b172a;
font-family: sans-serif;
}
#container {
height: 100vh;
display: flex;
align-items: center;
justify-content: center;
flex-direction: column;
padding: 5rem;
color: white;
text-transform: uppercase;
}
.clock-ctr {
position: relative;
border: 2px solid white;
height: 80vh;
width: 80vw;
padding: 10px;
display: flex;
justify-content: center;
align-items: center;
}
.hour-ctr {
grid-area: hour;
}
.min-ctr {
grid-area: min;
}
.sec-ctr {
grid-area: sec;
}
.ampm {
grid-area: ampm;
background: #bc4123;
}
.time-ctr {
position: absolute;
height: 70%;
width: 90%;
display: grid;
grid-template-columns: 1fr 1fr 1fr;
grid-template-rows: auto;
gap: 10px;
grid-template-areas: "hour min sec" "ampm ampm ampm";
}
h1 {
margin-bottom: 1rem;
letter-spacing: 8px;
font-size: 2.5rem;
}
.time-box {
background: #bc4123;
border-radius: 10px;
display: grid;
justify-items: center;
align-items: center;
height: auto;
text-align: center;
font-weight: bold;
font-size: calc(18px + 0.390625vw);
}
<div id="container">
<h1 class="clock-title">Clock</h1>
<div class="clock-ctr">
<div class="time-ctr">
<div class="hour-ctr time-box">
<p class="hour-value">00</p>
<p class="hour-title">Hour</p>
</div>
<div class="min-ctr time-box">
<p class="min-value">00</p>
<p class="min-title">Minute</p>
</div>
<div class="sec-ctr time-box">
<p class="sec-value">00</p>
<p class="sec-title">Second</p>
</div>
<p class="ampm time-box">AM</p>
</div>
</div>
</div>
the issue with the CSS code in the Stack Overflow question is that the left and right values for the #nav element are set to 0. This causes the element to take up the full width of its parent element, which is likely not the intended behavior.
To fix this issue, you can try setting the left and right values to auto like this:
#nav {
position: fixed;
top: 0;
left: auto;
right: auto;
width: 100%;
height: 60px;
background-color: white;
box-shadow: 0px 2px 4px rgba(0, 0, 0, 0.2);
z-index: 1000;
}
With this change, the #nav element will no longer take up the full width of its parent element and will instead be positioned at the top of the page with its width set to 100%.
So I am trying to wrap my head around css grid. What confuses me is the 'fr' unit on the row as I inspect the grid on the browser, '1fr . 834px'. I set on the main container, 'grid-template-rows: 1fr 1fr 1fr 1fr'. The grid just overblown. When I tried to put the 'height: 250px' in the header container , the column did change, but the row still hold the value 834px. Thus, there will be a huge white gap to the second row. I want it to be when I put the 'height: 250px' on the main container, the next bottom item will follow and stick to become the next column. How do I fix this ? Please help.
P.S : it has to be done only in grid, no flexbox.
Update : Solution found. Have to put height: 100vh on the container and thats it.
Below is my code:
<!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>Holy Grail Mockup</title>
<link rel="stylesheet" href="style.css">
</head>
<body>
<div class="container">
<div class="header">
<div class="logo">Header Logo</div>
<div class="menu">
<ul>
<li>header link one</li>
<li>header link two</li>
<li>header link three</li>
<li>header link four</li>
</ul>
</div>
</div>
<div class="sidebar">
<div class="photo">
<p>placeholder for image</p>
</div>
<div class="side-content">Box 1
</div>
<div class="side-content">Box 2
</div>
<div class="side-content">Box 3
</div>
</div>
<div class="nav">
<ul>
<li>Latest Articles</li>
<li>Most Views</li>
<li>Featured</li>
</ul>
</div>
</div>
</body>
</html>
* {
margin: 0;
padding: 0;
}
.container {
display: grid;
text-align: center;
grid-template-columns: 1fr 4fr;
grid-template-rows: 1fr 1fr 1fr 1fr;
gap: 4px;
overflow: hidden;
}
.container div {
padding: 15px;
font-size: 32px;
font-family: Helvetica;
font-weight: bold;
color: white;
}
.header {
display: grid;
background-color: #393f4d;
grid-template-columns: 20% 80%;
grid-column: 1/3;
height: 200px;
}
.logo {
display: grid;
justify-content: flex-start;
}
.menu ul,
.menu li {
display: grid;
white-space: nowrap;
align-items: flex-start;
grid-template-columns: repeat(4, 1fr);
font-size: 16px;
list-style: none;
margin-top: 8px;
margin-inline: 115px;
}
.sidebar {
display: grid;
grid-template-rows: repeat(4, 1fr);
background-color: #FF7755;
grid-column: 1/2;
grid-row: 2/4;
gap: 50px;
text-align: center;
}
.sidebar .photo {
display: grid;
align-items: center;
justify-items: center;
background-color: white;
color: black;
font-size: 12px;
font-weight: normal;
border-radius: 10px;
}
.sidebar .side-content {
display: grid;
align-items: center;
justify-items: center;
background-color: white;
color: black;
font-size: 16px;
font-weight: normal;
}
.nav {
display: grid;
background-color: #FF7755;
grid-template-columns: 100%;
grid-column: 2/3;
grid-row: 2/3;
height: 2vh;
}
.nav ul,
.nav li {
display: grid;
grid-auto-flow: column;
font-size: 16px;
text-transform: uppercase;
list-style: none;
}
.article {
display: grid;
background-color: #bccbde;
grid-column: 2/3;
grid-row: 3/4;
}
.article p {
font-size: 18px;
font-family: sans-serif;
color: white;
text-align: left;
}
.article .card {
background-color: #FFFFFF;
color: black;
text-align: center;
}
.card p {
color: black;
font-weight: normal;
font-size: 14px;
}
.card .title {
font-size: 18px;
text-align: center;
}
.footer {
background-color: #393f4d;
}
.footer p {
font-size: 13px;
font-weight: normal;
}
my design looks correct in firefox or chrome but wrong in safari. I don't understand why this is so. If I remove the 'align-items:center' it looks correct but why? I don't have a mac device so I can't try fixing it.
If you want to see what the real website looks like, link here:https://earslanyunus-statspreviewcard.netlify.app
And all codes
#import url("https://fonts.googleapis.com/css2?family=Inter:wght#400;700&family=Lexend+Deca&display=swap");
* {
padding: 0;
margin: 0;
box-sizing: border-box;
}
.soft-violet {
color: hsl(277, 64%, 61%);
}
.lexendDeca {
font-family: "Lexend Deca", "sans-serif";
font-weight: 400;
}
p,
a {
font-size: 15px;
}
html {
font-size: 62.5%;
}
body {
background-color: hsl(233, 47%, 7%);
font-family: "sans-serif", "Inter";
}
main {
display: flex;
align-items: center;
justify-content: center;
min-height: 100vh;
padding: 2rem;
flex-direction: column;
}
.card {
max-width: 120rem;
background-color: hsl(244, 38%, 16%);
border-radius: 10px;
display: -ms-grid;
display: grid;
-ms-grid-columns: 1fr 1fr;
grid-template-columns: 1fr 1fr;
overflow: hidden;
-webkit-box-align: center;
-ms-flex-align: center;
/*problem here*/
align-items: center;
}
.img-box {
height: 100%;
background-color: rgb(170, 92, 219);
background-image: url("stats-preview-card-component-main/images/image-header-desktop.jpg");
background-blend-mode: multiply;
background-size: cover;
}
.card-img {
width: 100%;
height: 100%;
opacity: 0.7;
}
.text-box {
padding: 7rem 9rem 7rem 7rem;
}
.title {
font-size: 4rem;
color: white;
}
.text-desc {
margin-top: 3rem;
color: hsla(0, 0%, 100%, 0.75);
line-height: 1.8;
font-size: 1.6rem;
}
.stat-box {
margin-top: 8rem;
display: -ms-grid;
display: grid;
grid-template-columns: repeat(3, 1fr);
}
.stats-num {
font-weight: 700;
color: white;
font-size: 2.5rem;
}
.stats-text {
font-size: 1.4rem;
color: hsla(0, 0%, 100%, 0.6);
margin-top: 0.2rem;
}
.footer,
.footer a {
font-size: 1.3rem;
color: white;
}
.footer a:link,
.footer a:visited {
color: white;
}
.footer a:hover,
.footer a:active {
color: hsl(277, 64%, 61%);
text-decoration: none;
}
.footer-box {
margin-top: 3rem;
}
#media all and (max-width: 59.6em) {
.text-box {
padding: 4rem 5rem 4rem 4rem;
}
}
#media all and (max-width: 50.7em) {
html {
font-size: 50%;
}
.card {
-ms-grid-columns: 1fr;
grid-template-columns: 1fr;
-ms-grid-rows: 1fr 2fr;
grid-template-rows: 1fr 2fr;
}
.img-box {
grid-row-start: 1;
}
.text-box {
padding: 3rem 5rem 3rem 3rem;
}
.stat-box {
grid-template-columns: 1fr;
grid-template-rows: repeat(3, 1fr);
justify-items: center;
row-gap: 2rem;
}
p {
text-align: center;
}
h1 {
text-align: center;
}
}
<!DOCTYPE html>
<html lang="en" dir="ltr">
<head>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta charset="utf-8">
<link rel="stylesheet" href="style.css">
<link rel="shortcut icon" href="stats-preview-card-component-main/images/favicon-32x32.png" type="image/x-icon">
<title>Stats Preview Card</title>
</head>
<body>
<main>
<div class="card">
<div class="text-box">
<h1 class="title">Get <span class="soft-violet">insights</span> that help your business grow.</h1>
<p class="text-desc lexendDeca">Discover the benefits of data analytics and make better decisions regarding revenue, customer experience, and overall efficiency.</p>
<div class="stat-box">
<div class="">
<p class="stats-num">10k+</p>
<p class="stats-text lexendDeca">COMPANIES</p>
</div>
<div class="">
<p class="stats-num">314</p>
<p class="stats-text lexendDeca">TEMPLATES</p>
</div>
<div class="">
<p class="stats-num">12M+</p>
<p class="stats-text lexendDeca">QUERIES</p>
</div>
</div>
</div>
<div class="img-box">
<!-- <img class="card-img" src="stats-preview-card-component-main/images/image-header-desktop.jpg" alt=""> -->
</div>
</div>
<div class="footer-box">
<p class="footer text-align-center">Challenge by Frontend Mentor</p>
<p class="footer text-align-center">Coded by Yunus Emre Arslan</p>
</div>
</main>
</body>
</html>
To get the consistency between Chrome / Firefox and Safari :
Remove align-items: center; on the .card element
Remove height:100%; on .img-box element
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>
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.