Reducing Gap in CSS Grid UL/LI - html

I am having some issues reducing the space on my footer using CSS grid. I've gotten to the point where my list items are on one line but I cannot find a way to reduce the gap in between. This may be because of my centering of it but I cannot figure it out after googling/playing.
https://codepen.io/DanielPeterHill/pen/pxjpzM
html,
body {
width: 100%;
height: 100%;
margin: 0;
}
body {
font-family: 'Oswald', sans-serif;
color: #FEDCD2;
}
.nav-container {
width: 100%;
background: #DF744A;
margin: 0;
}
nav {
max-width: 1720px;
margin: 0 auto;
display: grid;
grid-template-columns: 1fr auto 1fr;
}
.left-menu {
grid-column: 1;
align-self: center;
}
.logo {
grid-column: 2;
}
#nav-toggle,
.burger-menu {
display: none;
}
nav a {
color: white;
text-decoration: none;
text-transform: uppercase;
transition: .3s all ease-in-out;
}
nav a:hover {
opacity: .7;
color: blue;
}
.left-menu a {
padding: 10px 0;
margin-left: 15px;
font-size: 14px;
font-weight: 300;
letter-spacing: 0.5px;
}
.logo {
font-size: 40px;
padding: 1rem;
}
.burger-menu {
grid-column: 1;
align-self: center;
margin-left: 20px;
}
.footer {
position: fixed;
left: 0;
bottom: 0;
width: 100%;
background-color: #DF744A;
color: white;
text-align: center;
}
footer {
display: grid;
grid-template-rows: auto 3fr auto;
}
.footer-left {
grid-column: 1;
align-self: center;
}
.footer-right {
grid-column: 3;
align-self: center;
list-style-type: none;
display: grid;
grid-template-columns: 1fr 1fr 1fr 1fr;
grid-row-gap: 50px;
}
.footer-right li {
text-decoration: none;
}
.footer-right li a {
color: white;
}
.footer-right li a:hover {
opacity: .7;
color: blue;
}
.underlineremove {
text-decoration: none;
text-decoration-style: none;
}
#media only screen and (max-width: 1025px) {
.burger-menu {
display: inline-block;
width: 40px;
}
.left-menu {
display: none;
}
#nav-toggle:checked~.left-menu {
display: grid;
grid-row: 2;
}
}
<link href="https://fonts.googleapis.com/css?family=Oswald:600" rel="stylesheet">
<div class="nav-container">
<nav>
<input type="checkbox" id="nav-toggle">
<label for="nav-toggle" class="burger-menu">
<img src="images/hamburger.png" alt="">
</label>
<div class="left-menu">
Shop
Blog
About
Contact
</div>
Dill's Delight's
</nav>
</div>
<div class="footer">
<footer>
<p class="footer-left"> © FarHill Deisgns </p>
<ul class="footer-right">
<li>TEST</li>
<li>TEST</li>
<li>TEST</li>
<li>TEST</li>
</ul>
</footer>
</div>
My example is above and any help would be amazing! My outcome would be to be able to reduce the gap beween the 4 TESTS in the bottom right to make it look a bit cleaner.
Thank you,
Dan

You can try this:
.footer-right
{
grid-column: 3;
align-self: center;
list-style-type: none;
display: grid;
grid-template-columns: repeat(4, 50px);
grid-row-gap: 50px;
}
I changed grid template columns to this grid-template-columns: repeat(4, 50px); to give to the columns 50px width. But, if this does not suite you, you can always use some other width in % or in some other measure.

One option...don't use CSS-Grid at all on the footer. Flexbox would be simpler.
html,
body {
width: 100%;
height: 100%;
margin: 0;
}
body {
font-family: 'Oswald', sans-serif;
color: #FEDCD2;
}
.footer {
/* not required for demo
position: fixed;
left: 0;
bottom: 0;
width: 100%;
*/
background-color: #DF744A;
color: white;
text-align: center;
}
footer {
display: flex;
}
.footer-left {
grid-column: 1;
align-self: center;
}
.footer-right {
margin-left: auto;
list-style-type: none;
display: flex;
}
.footer-right li {
text-decoration: none;
margin: .25em;
/* manages spacing */
}
.footer-right li a {
color: white;
}
.footer-right li a:hover {
opacity: .7;
color: blue;
}
.underlineremove {
text-decoration: none;
text-decoration-style: none;
}
<div class="footer">
<footer>
<p class="footer-left"> © FarHill Deisgns </p>
<ul class="footer-right">
<li>TEST</li>
<li>TEST</li>
<li>TEST</li>
<li>TEST</li>
</ul>
</footer>
</div>
Alternatively, if you must use CSS-Grid, then consider a two column grid and flex the ul...
footer {
display: grid;
grid-template-columns:1fr auto;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
}
body {
font-family: 'Oswald', sans-serif;
color: #FEDCD2;
}
.footer {
/* not required for demo
position: fixed;
left: 0;
bottom: 0;
width: 100%;
*/
background-color: #DF744A;
color: white;
text-align: center;
}
footer {
display: grid;
grid-template-columns: 1fr auto;
}
.footer-left {
grid-column: 1;
align-self: center;
}
.footer-right {
margin-left: auto;
list-style-type: none;
display: flex;
}
.footer-right li {
text-decoration: none;
margin: .25em;
}
.footer-right li a {
color: white;
}
.footer-right li a:hover {
opacity: .7;
color: blue;
}
.underlineremove {
text-decoration: none;
text-decoration-style: none;
}
<div class="footer">
<footer>
<p class="footer-left"> © FarHill Deisgns </p>
<ul class="footer-right">
<li>TEST</li>
<li>TEST</li>
<li>TEST</li>
<li>TEST</li>
</ul>
</footer>
</div>

Related

Grid areas in navigation bar pushed horizontally

I tried to add the changes I've made to a web page for the navigation bar, but the layout is messed up. For some reason, the columns have all been moved over by 1 fraction, and the menu burger "buns" are now out of place. Here is some of the code for the navigation elements:
HTML Code
<!doctype html>
<html>
<head>
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="design.css">
<link rel="preconnect" href="https://fonts.googleapis.com">
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
<link href="https://fonts.googleapis.com/css2?family=Comfortaa&display=swap" rel="stylesheet">
</head>
<body>
<div class="container">
<div class="item logo">
<h3><a class="myName" href="/index.html">BALLOONS</a></h3>
</div>
<div class="item links">
<ul class="navigation">
<li>Home</li>
<li>About
</li>
<li>Maps</li>
<li>Tours</li>
<li>Contact</li>
</ul>
</div>
<div class="item menu">
<div class="menu-btn">
<div id="middle" class="btn-mid"></div>
</div>
<script src="response.js"></script>
</div>
<div class="item content"></div>
<div class="item footer">
<div>
<br><br>
<ul class="nav_footer">
<li>Home</li>
<li>About
</li>
<li>Maps</li>
<li>Tours</li>
<li>Contact
</li>
</ul>
</div>
</div>
</div>
</body>
CSS Code
.container {
display: grid;
grid-template-columns: repeat(8, 1fr);
grid-template-rows: repeat(5, 1fr);
}
.logo {
grid-area: logo;
display: flex;
grid-row: span 1;
grid-column: span 2;
margin: 2px;
background-color: black;
justify-content: center;
align-items: center;
}
.myName {
font-family: "Comfortaa";
text-decoration: none;
color: white;
}
.myName:hover {
cursor: pointer;
}
.links {
grid-area: links;
grid-column: span 5;
grid-row: span 1;
display: flex;
overflow: hidden;
justify-content: center;
align-items: center;
margin: 2px;
background-color: black;
}
.navigation {
display: flex;
direction: row;
justify-content: space-around;
padding: 0; //By default, padding is set
list-style-type: none;
width: 80%; //Adds more spacing
}
.navigation a {
color: white;
text-decoration: none;
}
.navigation a:hover {
text-decoration: underline;
}
.navigation li {
display: inline-block;
}
.menu {
grid-area: menu;
grid-column: span 1;
grid-row: span 1;
display: flex;
padding: 0;
margin: 2px;
background-color: black;
justify-content: center;
align-items: center;
}
.menu-btn {
display: flex;
justify-content: center;
align-items: center;
width: 80%;
height: 80%;
transition: all .5s ease-in-out;
}
.btn-mid {
position: relative;
width: 25px;
height: 3px;
background: #fff;
border-radius: 2px;
transition: all .5s ease-in-out;
}
.btn-mid::before,
.btn-mid::after {
position: absolute;
/*Necessary for 3 bars*/
content: '';
width: 25px;
height: 3px;
background: #fff;
border-radius: 2px;
transition: all .5s ease-in-out;
}
.btn-mid::before {
transform: translateY(-300%);
}
.btn-mid::after {
transform: translateY(300%);
}
/*BUTTON ANIMATION*/
.menu-btn.open .btn-mid {
transform: translateX(-175%);
background: transparent;
}
.menu-btn.open .btn-mid::before {
transform: rotate(45deg) translate(125%, -1050%);
}
.menu-btn.open .btn-mid::after {
transform: rotate(-45deg) translate(125%, 1050%);
}
/*END*/
.content {
grid-area: content;
grid-column: span 8;
grid-row: span 3;
padding-top: 15%;
background-image: url("https://i.stack.imgur.com/xkpSw.jpg");
background-repeat: no-repeat;
-webkit-background-size: cover;
-moz-background-size: cover;
-o-background-size: cover;
background-size: cover;
height: 25vh;
}
.footer {
grid-area: footer;
grid-column: span 8;
grid-row: span 1;
padding-top: 15%;
}
h1 {
font-family: "Comfortaa";
text-align: center;
}
h3, h4, p, label {
font-family: "Comfortaa";
}
.navigation {
padding: 5%;
overflow: hidden;
background-color: black;
display: flex;
direction: row;
justify-content: space-around;
font-family: "Comfortaa";
}
#media screen and (max-width: 600px) {
.links {
display: none;
}
.logo {
grid-column: span 7;
grid-row: span 1;
}
.navigation a {
display: none;
}
}
#media screen and (min-width: 601px) {
.navigation li {
font-family: "Comfortaa";
}
.navigation a {
color: white;
}
}
div {
text-align: center;
}
.nav_footer {
margin: 0;
padding: 0;
overflow: hidden;
text-align: center;
}
.nav_footer li {
display: inline;
font-family: "Comfortaa";
}
.nav_footer a {
color: black;
}
ul {
list-style-type: none;
}
li {
font-family: "Comfortaa";
}
But aside from navigation, everything else displays fine, and the animation works as expected. I've included two screenshots.
The first is from a mobile view:
The second is from a desktop view:
I entered my code in codepen, and while the menu burger is still messed up, all of the areas fit in the same row like they're supposed to. What am I doing wrong?
You can use display:flex instead of display:grid. Just add this lines to your CSS.
.container {
display: flex;
background:black;
justify-content:space-between;
}

HTML Form causing second vertical scroll bar until form is in viewport

I'm having an issue with a form in my HTML footer, it seems to be causing a second scroll bar on the vertical axis, does anyone have any suggestions on how to eliminate this second scroll bar issue?
I've tried a few different rearrangements, it seems once I comment out the form that it fixes my issue perfectly, so I've definitely isolated the problem to the form itself, what am I missing?
codepen: https://codepen.io/roomwillow/pen/WNoVoOq
HTML:
<div class="top"></div>
<footer>
<div id="footerFlexContainer">
<div id="leftFooterFlex">
<img id="footerLogo" src="content/logos/dig-500x-white.png" alt="Logo">
<div id="menu3" class="footerMenus">
<ul>
<li> Sitemap </li>
<li class="menu3div">
<p>|</p>
</li>
<li> Legal </li>
<li class="menu3div">
<p>|</p>
</li>
<li>
<p>Copyright 2021</p>
</li>
<li class="menu3div">
<p>|</p>
</li>
<li>
<p>Company Ltd.</p>
</li>
</ul>
</div>
</div>
<div id="rightFooterFlex">
<ul id="menu4" class="footerMenus">
<li>Speed Test</li>
<li>Project Send</li>
</ul>
<p id="newsletterTitle">Subscribe To Our Newsletter:</p>
<form id="newsletterForm">
<input type="text" id="email" name="email">
<input type="submit" value="Submit">
</form>
<ul id="socialGrey" class="social">
<li><img class="hovGrey" src="content/images/footer/facebookHover.png"></li>
<li><img class="hovGrey" src="content/images/footer/instagramHover.png"></li>
<li><img class="hovGrey" src="content/images/footer/linkedinHover.png"></li>
<li><img class="hovGrey" src="content/images/footer/twitterHover.png"></li>
<li><img class="hovGrey youtube" src="content/images/footer/youtubeHover.png"></li>
</ul>
<ul id="socialWhite" class="social">
<li><img class="hovWhite" src="content/images/footer/facebook.png"></li>
<li><img class="hovWhite" src="content/images/footer/instagram.png"></li>
<li><img class="hovWhite" src="content/images/footer/linkedin.png"></li>
<li><img class="hovWhite" src="content/images/footer/twitter.png"></li>
<li><img class="hovWhite youtube" src="content/images/footer/youtube.png"></li>
</ul>
</div>
</div>
</footer>
CSS:
html, body {
width: 100%;
height: 100%;
margin: 0;
padding: 0;
overflow-x: hidden;
}
/*Text*/
h1{
font-weight: bold;
font-size: 22pt;
}
h2 {
font-weight: bold;
letter-spacing: 0.01em;
font-size: 2.5rem;
margin: 0;
}
h3 {
font-weight: bold;
font-size: 18pt;
line-height: 30px;
margin: 0;
}
p {
font-size: 1.08rem;
letter-spacing: 0.02em;
font-weight: 100;
margin: 0;
}
body {
font-family: Arial, Helvetica, sans serif;
color: white;
}
.top {
background-color: purple;
height: 1900px;
}
/* Black on White */
.button1 {
padding: 0.5rem 1rem 0.5rem 1rem;
border: solid white 1px;
display: inline-block;
text-decoration: none;
color: white;
}
.button1:hover {
background-color: white;
color: black;
}
/* White on Black */
.button2 {
padding: 0.5rem 1rem 0.5rem 1rem;
border: solid black 2px;
display: inline-block;
text-decoration: none;
color: black;
}
.button2:hover {
background-color: black;
color: white;
}
/* CSS Document */ /* Footer */
ul {
padding: 0;
list-style-type: none;
margin: 0;
}
#footerFlexContainer {
margin-top: 1rem;
display: flex;
background-color: black;
overflow: hidden;
}
#leftFooterFlex {
flex: 1 0 auto;
width: auto;
display: grid;
grid-template-columns: auto;
}
#rightFooterFlex {
flex: 1 0 auto;
width: auto;
display: grid;
grid-template-columns: auto;
align-items: end;
justify-items: end;
}
.footerMenus a{
text-decoration: none;
color: white;
font-size: 1.08rem;
letter-spacing: 0.02em;
font-weight: 100;
}
.footerMenus a:hover{
color: lightgrey;
}
#menu3 {
grid-area: 2 / 1 / 3 / 2;
margin-bottom: 1rem;
}
#menu3 li {
display: inline-block;
margin-right: 0.5rem;
}
#menu4 {
grid-area: 1 / 1 / 2 / 2;
}
#menu4 li {
margin-bottom: 1.15rem;
}
#newsletterTitle {
grid-area: 2 / 1 / 3 / 2;
align-self: start;
}
#newsletterForm {
grid-area: 2 / 1 / 3 / 2;
}
#rightFooterFlex input[type=text] {
padding: 0.25rem;
width: 10rem;
margin-right: 0.5rem;
outline: none;
} /*Form Input Field*/
#rightFooterFlex input[type=button], input[type=submit] {
padding: 0.35rem 0.7rem;
background-color: black;
color: white;
border: 1px solid white;
} /*Form Submit Button (Non Hover)*/
#rightFooterFlex input[type=button], input[type=submit]:hover {
padding: 0.35rem 0.7rem;
background-color: white;
color: black;
border: 1px solid white;
cursor: pointer;
} /*Form Submit Button (Hover)*/
.social {
grid-area: 3 / 1 / 4 / 2;
}
.social li {
display: inline-block;
margin-left: 0.5rem;
}
#socialWhite li:hover {
opacity: 0;
}
.social img {
height: 2.25rem;
}
#media only screen and (min-width: 865px) {
#footerFlexContainer {
height: 18rem;
}
#leftFooterFlex {
grid-template-rows: 75% 25%;
margin-left: 2.25rem;
}
#menu3 {
align-self: end;
}
#footerLogo {
height: 10rem;
grid-area: 1 / 1 / 2 / 2;
align-self: end;
margin-bottom: 0.5rem;
}
#rightFooterFlex {
margin-right: 2.25rem;
text-align: right;
grid-tempate-rows: 2fr 3.5rem 1fr;
}
.social li {
margin-bottom: 1rem;
}
}
#media only screen and (max-width: 865px) {
#footerFlexContainer {
flex-flow: column nowrap;
}
#leftFooterFlex {
order: 2;
grid-template-rows: 100%;
margin-left: 1.5rem;
height: auto;
}
#menu3 {
grid-area: 1 / 1 / 2 / 2;
align-self: end;
}
#rightFooterFlex {
margin-right: 0;
margin-left: 1.5rem;
justify-items: start;
height: 14.5rem;
grid-template-rows: auto 3.5rem 4.25rem;
}
#footerLogo {
display: none;
}
#menu3 {
align-self: center;
margin-top: 1rem;
}
#menu3 li {
display: block;
margin-bottom: 1.15rem;
}
.menu3div {
display: none;
}
}
your answer in short: Use display and overflow properties
For the long answer, visit these websites:
CSS overflow
CSS Display property
Issue was in Firefox v86, fixed by updating to v86.0.1

Currently struggling to use media queries to create dynamic layout changes when screen sizes change

I've managed to become ok at HTML and CSS and would like some assistance making this code responsive in the way I've designed it in photoshop. But media queries keep getting override and I would love some guidance into how to overcome and also how to make my code better for what I am trying to achieve.
#import url('https://fonts.googleapis.com/css2?family=Londrina+Solid:wght#300&display=swap');
html * {
margin: 0;
padding: 0;
box-sizing: border-box;
}
ul li {
list-style: none;
}
.midsmallprint {
margin-top: 5px;
display: flex;
justify-content: center;
text-align: center;
font-size: x-small;
font-family: Arial, Helvetica, sans-serif
}
.midimageingre ul li:nth-child(1) {
background-color: #f1d036;
}
.midimageingre ul li:nth-child(2) {
background-color: #72c789;
}
.midimageingre ul li:nth-child(3) {
background-color: #d04a30;
}
.midimageingre ul li:nth-child(4) {
background-color: #e7e1c5;
}
.midimageingre ul li:nth-child(5) {
background-color: #2c7841;
}
.midimageingre ul li:nth-child(6) {
background-color: #c55f4b;
}
/* mid carousel*/
.midtopcarousel ul {
width: 600px;
overflow-x: scroll;
overflow-y: hidden;
white-space: nowrap;
}
.midtopcarousel ul li {
margin-top: 10px;
margin-left: 10px;
display: inline-block;
width: 100px;
height: 100px;
border-radius: 10px;
background-color: #ffffff;
}
.midtopcarousel ul li span {
font-weight: bold;
font-family: SF Pro Display;
float: right;
margin-right: 5px;
}
/* mid image header */
.midimage ul li h1 {
margin-top: 5px;
display: flex;
font-family: "Londrina Solid", cursive;
justify-content: center;
}
/* mid big image */
.midimage {
margin-top: 10px;
margin-left: 10px;
display: inline-block;
width: 360px;
height: 350px;
border-radius: 10px;
background-color: #ffffff;
}
.midsection .midimage li span {
font-family: SF Pro Display;
float: right;
margin-right: 5px;
}
/* mid INGREDIENTS */
.midimageingre ul li span {
font-family: SF Pro Display;
margin-left: 10px;
color: #ffffff;
}
.midimageingre ul li .price {
font-weight: 900;
font-family: "Barlow Condensed", sans-serif;
color: rgb(255, 255, 255);
display: inline-block;
}
.midimageingre ul li .ingname {
text-align: center;
vertical-align: middle;
line-height: normal;
margin-right: 20px;
float: right;
color: #ffffff;
display: inline-block;
}
.midimageingre ul {
display: grid;
clear: both;
grid-template-columns: 1fr;
grid-row-gap: 26px;
grid-column-gap: 0px;
float: right;
font-family: "Londrina Solid", cursive;
margin-right: 10px;
margin-top: 10px;
clear: none;
}
.midimageingre ul li {
border-radius: 5px;
width: 200px;
font-size: 20px;
height: 30px;
background: #555;
}
.midsection {
margin-right: 15px;
margin-left: 15px;
display: inline-block;
border-radius: 5px;
min-width: 600px;
height: 500px;
background-color: #f0efef;
}
#media only screen and (max-width:540px) {
.midsmallprint {
margin-top: 10px;
color: #e5509a;
display: flex;
justify-content: center;
text-align: center;
font-size: x-small;
font-family: Arial, Helvetica, sans-serif
}
.midsection {
padding-right: 20px;
height: 50px;
border-radius: 5px;
background-color: #f1ed00;
min-width: 100%;
}
.midimage {
margin-top: 10px;
margin-left: 10px;
display: inline-block;
width: 100%;
height: 360px;
border-radius: 10px;
background-color: #ffffff;
}
.midimageingre ul li span {
font-family: SF Pro Display;
margin-left: 10px;
color: #ffffff;
}
.midimageingre ul li .price {
font-weight: 900;
font-family: "Barlow Condensed", sans-serif;
color: rgb(255, 255, 255);
display: inline-block;
}
.midimageingre ul li .ingname {
text-align: center;
vertical-align: middle;
line-height: normal;
margin-right: 20px;
float: right;
color: #ffffff;
display: inline-block;
}
.midimageingre ul li {
border-radius: 5px;
width: 200px;
font-size: 20px;
height: 30px;
background: rgb(125, 214, 103);
margin: 10px;
}
}
li {
list-style: none;
}
#media screen and (max-width: 1100px) {
.midimage {}
.midimageingre ul {}
.midimageingre ul li {}
.left li {
font-size: 13px;
font-family: Arial, Helvetica, sans-serif;
color: white;
}
/* showcase */
.midsection {
margin-left: 10px;
margin-right: 10px;
order: 3;
height: 100%;
border-radius: 5px;
min-width: 100%;
}
}
<div class="midsection">
<div class="midtopcarousel">
<ul>
<li><span>x</span></li>
<li><span>x</span></li>
<li><span>x</span></li>
</ul>
</div>
<div class="midimageingre">
<ul>
<li><span>x</span>
<div class="price">50p</div>
<div class="ingname ">CHEESE</div>
</li>
<li><span>x</span>
<div class="price">50p</div>
<div class="ingname ">LETTUCE</div>
</li>
<li><span>x</span>
<div class="price">50p</div>
<div class="ingname ">TOMATOES</div>
</li>
<li><span>x</span>
<div class="price">50p</div>
<div class="ingname ">ONIONS</div>
</li>
<li><span>x</span>
<div class="price">50p</div>
<div class="ingname ">CUCUMBERS</div>
</li>
<li><span>x</span>
<div class="price">50p</div>
<div class="ingname ">SAUCE</div>
</li>
</ul>
</div>
<div class="midimage">
<ul>
<li>
<span>x</span>
</li>
<li>
<h1>Name Of Burger</h1>
</li>
</ul>
</div>
<div class="midsmallprint">* alterations to items will affect price</div>
</div>
UPDATE: Based on the Edit from OP (i-e Images provided) I have updated my code to work for all the 4 break-points. Here is the updated Code:)
CODEPEN LINK : https://codepen.io/emmeiWhite/pen/mdrLMde
#import url("https://fonts.googleapis.com/css2?family=Londrina+Solid:wght#300&display=swap");
* {
margin: 0;
padding: 0;
box-sizing: border-box;
}
ul li {
list-style: none;
}
.midsection {
width: 100vw;
display: flex;
justify-content: space-between;
}
.midsmallprint {
margin-top: 5px;
display: flex;
justify-content: center;
text-align: center;
font-size: x-small;
font-family: Arial, Helvetica, sans-serif;
}
.midimageingre {
display: grid;
grid-template-columns: 2fr 1fr;
column-gap: 2rem;
}
.midimageingre ul li:nth-child(1) {
background-color: #f1d036;
}
.midimageingre ul li:nth-child(2) {
background-color: #72c789;
}
.midimageingre ul li:nth-child(3) {
background-color: #d04a30;
}
.midimageingre ul li:nth-child(4) {
background-color: #e7e1c5;
}
.midimageingre ul li:nth-child(5) {
background-color: #2c7841;
}
.midimageingre ul li:nth-child(6) {
background-color: #c55f4b;
}
/* mid carousel*/
.midtopcarousel ul li {
margin-top: 10px;
margin-left: 10px;
display: inline-block;
width: 100px;
height: 100px;
border-radius: 10px;
background-color: #ffffff;
}
.midtopcarousel ul li span {
font-weight: bold;
font-family: SF Pro Display;
float: right;
margin-right: 5px;
}
/* mid image header */
.midimage ul li {
margin-top: 5px;
font-family: "Londrina Solid", cursive;
background-color: transparent !important;
}
.midimage ul li span {
color: #000 !important;
}
/* mid big image */
.midimage {
margin-top: 10px;
margin-left: 10px;
min-height: 75vh;
border-radius: 10px;
background-color: #ffffff;
}
.sidebar {
padding: 2rem;
display: grid;
grid-template-columns: 1fr;
}
.sidebar li {
display: flex;
justify-content: space-around;
align-items: center;
width: 100%;
}
.midsection .midimage li span {
font-family: SF Pro Display;
margin-right: 5px;
}
/* mid INGREDIENTS */
.midimageingre ul li span {
font-family: SF Pro Display;
margin-left: 10px;
color: #ffffff;
}
.midimageingre ul li .price {
font-weight: 900;
font-family: "Barlow Condensed", sans-serif;
color: rgb(255, 255, 255);
/* display: inline-block; */
}
.midimageingre ul li .ingname {
text-align: center;
vertical-align: middle;
line-height: normal;
margin-right: 20px;
color: #ffffff;
}
.midimageingre ul {
font-family: "Londrina Solid", cursive;
margin-right: 10px;
margin-top: 10px;
}
.midimageingre ul li {
border-radius: 5px;
font-size: 20px;
height: 50px;
background: #555;
margin: 1rem 0.5rem;
}
.sidebar li {
display: flex !important;
margin: 1rem 0 !important;
justify-content: space-around !important;
align-items: center !important;
width: 100% !important;
}
.midsection {
margin-right: 15px;
margin-left: 15px;
display: inline-block;
border-radius: 5px;
min-width: 600px;
min-height: 100vh;
background-color: #f0efef;
}
#media screen and (max-width: 540px) {
.midimageingre {
grid-template-columns: 1fr;
grid-auto-rows: repeat(2, 1fr);
}
.midimageingre .sidebar {
order: -1;
}
}
#media screen and (max-width: 800px) {
.midimageingre .sidebar {
order: 1;
grid-template-columns: 1fr !important;
}
}
#media screen and (max-width: 1200px) {
.midimageingre .sidebar {
grid-template-columns: repeat(2, 1fr);
column-gap: 1rem;
}
}
<!DOCTYPE html>
<html>
<head>
<title>Home Page</title>
<meta charset="UTF-8" />
<link rel="preconnect" href="https://fonts.gstatic.com" />
<link
href="https://fonts.googleapis.com/css2?family=Quantico&display=swap"
rel="stylesheet"
/>
<link rel="stylesheet" href="./style.css" />
</head>
<body>
<div class="midsection">
<div class="midtopcarousel">
<ul>
<li><span>x</span></li>
<li><span>x</span></li>
<li><span>x</span></li>
</ul>
</div>
<div class="midimageingre">
<div class="midimage">
<ul>
<li>
<span>x</span>
</li>
<li>
<h1>Name Of Burger</h1>
</li>
</ul>
</div>
<ul class="sidebar">
<li>
<span>x</span>
<div class="price">50p</div>
<div class="ingname">CHEESE</div>
</li>
<li>
<span>x</span>
<div class="price">50p</div>
<div class="ingname">LETTUCE</div>
</li>
<li>
<span>x</span>
<div class="price">50p</div>
<div class="ingname">TOMATOES</div>
</li>
<li>
<span>x</span>
<div class="price">50p</div>
<div class="ingname">ONIONS</div>
</li>
<li>
<span>x</span>
<div class="price">50p</div>
<div class="ingname">CUCUMBERS</div>
</li>
<li>
<span>x</span>
<div class="price">50p</div>
<div class="ingname">SAUCE</div>
</li>
</ul>
</div>
<div class="midsmallprint">* alterations to items will affect price</div>
</div>
There are couple of things I would like to point.
Using floats when you are using flexbox and grids doesn't make much sense. Flexbox and CSS-Grids came to overcome the issues that were there in the float layouts.
Media Queries should be used properly in a way that One of the Layout is ready say a Desktop Layout is ready. Then we need pretty small small changes in our media queries as per our small screen, because all the CSS is already there. We just need to change only those things that we don't need on smaller screens.
I have made a CODEPEN Demo for your code :) Changed HTML Element positions a bit, Removed un-necessary CSS like floats. And now you can build on top of it :)

How to make navbar stay fixed when scrolling

My problem is when I try to make navbar fixed ,it just disappear from my page .First thing that I've tried is to create a class called sticky that has position:fixed but when I call it my navbar stop showing ( I think it shrinks so much that text can be visible). Any ideas how to make the navbar static when user scrolls down ?
HTML CODE
</head>
<body>
<!-- Navbar -->
<div class ="main">
<div class="navbar ">
<div class="container flex lead ">
<nav>
<ul>
<li>Acasa</li>
<li>Proiecte</li>
<li>Recenzii</li>
</ul>
</nav>
<div>
<h1>CarolHousing</h1>
</div>
<div class="social sm">
<i class="fab fa-facebook fa-2x"></i>
<i class="fab fa-instagram fa-2x"></i>
Contact
</div>
</div>
</div>
</div>
<!-- Showcase -->
<section class="showcase">
<div class="container grid">
<div class="showcase-text">
<h1>Easier Deployment</h1>
<p>Deploy web apps of all kinds, from large scale enterprise APIs to static websites for individuals. Fill out the form to try a demo of our platform</p>
Read More
</div>
<div class="showcase-form card">
<h2>Request a Demo</h2>
<form>
<div class="form-control">
<input type="text" name="name" placeholder="Name" required>
</div>
<div class="form-control">
<input type="text" name="company" placeholder="Company Name" required>
</div>
<div class="form-control">
<input type="email" name="email" placeholder="Email" required>
</div>
<input type="submit" value="Send" class="btn btn-primary">
</form>
</div>
</div>
</section>
<!-- Cli -->
<section class="cli">
<div class="container grid">
<img src="images/cli.png" alt="">
<div class="card">
<h3>Easy to use, cross platform CLI</h3>
</div>
<div class="card">
<h3>Deploy in seconds</h3>
</div>
</div>
</section>
<!-- Footer -->
<footer class="footer bg-dark py-5">
<div class="container grid grid-3">
<div>
<h1>Loruki
</h1>
<p>Copyright © 2020</p>
</div>
<nav>
<ul>
<li>Home</li>
<li>Features</li>
<li>Docs</li>
</ul>
</nav>
<div class="social">
<i class="fab fa-facebook fa-2x"></i>
<i class="fab fa-instagram fa-2x"></i>
</div>
</div>
</footer>
</body>
</html>
CSS CODE:
.navbar {
background-color: var(--primary-color);
color: #fff;
min-height: 80px;
position: sticky;
top: 0;
}
.navbar ul {
display: flex;
flex-direction: row;
flex-grow:1;
}
.navbar a {
color: #fff;
padding: 10px;
margin: 0 2px;
}
.navbar a:hover {
border-bottom: 2px #fff solid;
}
.navbar .flex {
justify-content:space-between;
}
.navbar .social a{
margin: 0 2px;
flex-grow:1;
}
.navbar .social > *:nth-child(3){
font-size: 28px;
}.showcase {
height: 400px;
background-color: var(--primary-color);
color: #fff;
position: relative;
}
.showcase h1 {
font-size: 40px;
}
.showcase p {
margin: 20px 0;
}
.showcase .grid {
overflow: visible;
grid-template-columns: 55% auto;
gap: 30px;
}
.showcase-text {
animation: slideInFromLeft 1s ease-in;
}
.showcase-form {
position: relative;
top: 60px;
height: 350px;
width: 400px;
padding: 40px;
z-index: 100;
justify-self: flex-end;
animation: slideInFromRight 1s ease-in;
}
.showcase-form .form-control {
margin: 30px 0;
}
.showcase-form input[type='text'],
.showcase-form input[type='email'] {
border: 0;
border-bottom: 1px solid #b4becb;
width: 100%;
padding: 3px;
font-size: 16px;
}
.showcase-form input:focus {
outline: none;
}
.showcase::before,
.showcase::after {
content: '';
position: absolute;
height: 100px;
bottom: -70px;
right: 0;
left: 0;
background: #fff;
transform: skewY(-3deg);
-webkit-transform: skewY(-3deg);
-moz-transform: skewY(-3deg);
-ms-transform: skewY(-3deg);
}
#import url('https://fonts.googleapis.com/css2?family=Lato:wght#300&display=swap');
:root {
--primary-color: #047aed;
--secondary-color: #1c3fa8;
--dark-color: #002240;
--light-color: #f4f4f4;
--success-color: #5cb85c;
--error-color: #d9534f;
}
* {
box-sizing: border-box;
padding: 0;
margin: 0;
}
body {
font-family: 'Lato', sans-serif;
color: #333;
line-height: 1.6;
}
ul {
list-style-type: none;
}
a {
text-decoration: none;
color: #333;
}
h1,
h2 {
font-weight: 300;
line-height: 1.2;
margin: 10px 0;
}
p {
margin: 10px 0;
}
img {
width: 100%;
}
code,
pre {
background: #333;
color: #fff;
padding: 10px;
}
.hidden {
visibility: hidden;
height: 0;
}
/* Features */
.features-head img,
.docs-head img {
width: 200px;
justify-self: flex-end;
}
.features-sub-head img {
width: 300px;
justify-self: flex-end;
}
.features-main .card > i {
margin-right: 20px;
}
.features-main .grid {
padding: 30px;
}
.features-main .grid > *:first-child {
grid-column: 1 / span 3;
}
.features-main .grid > *:nth-child(2) {
grid-column: 1 / span 2;
}
/* Docs */
.docs-main h3 {
margin: 20px 0;
}
.docs-main .grid {
grid-template-columns: 1fr 2fr;
align-items: flex-start;
}
.docs-main nav li {
font-size: 17px;
padding-bottom: 5px;
margin-bottom: 5px;
border-bottom: 1px #ccc solid;
}
.docs-main a:hover {
font-weight: bold;
}
/* Tablets and under */
#media (max-width: 768px) {
.grid,
.showcase .grid,
.stats .grid,
.cli .grid,
.cloud .grid,
.features-main .grid,
.docs-main .grid {
grid-template-columns: 1fr;
grid-template-rows: 1fr;
}
.showcase {
height: auto;
}
.showcase-text {
text-align: center;
margin-top: 40px;
animation: slideInFromTop 1s ease-in;
}
.showcase-form {
justify-self: center;
margin: auto;
animation: slideInFromBottom 1s ease-in;
}
.cli .grid > *:first-child {
grid-column: 1;
grid-row: 1;
}
.features-head,
.features-sub-head,
.docs-head {
text-align: center;
}
.features-head img,
.features-sub-head img,
.docs-head img {
justify-self: center;
}
.features-main .grid > *:first-child,
.features-main .grid > *:nth-child(2) {
grid-column: 1;
}
}
/* Mobile */
#media (max-width: 500px) {
.navbar {
height: 110px;
}
.navbar .flex {
flex-direction: column;
}
.navbar ul {
padding: 10px;
background-color: rgba(0, 0, 0, 0.1);
}
.showcase-form {
width: 300px;
}
}.container {
max-width: 1400px;
margin: 0 auto;
overflow: auto;
padding: 0 40px;
align-self: start;
}
.main {
min-height: 100vh; /*add*/
height: 3000px; /*this is a test rule*/
}
.card {
background-color: #fff;
color: #333;
border-radius: 10px;
box-shadow: 0 3px 10px rgba(0, 0, 0, 0.2);
padding: 20px;
margin: 10px;
}
.btn {
display: inline-block;
padding: 10px 30px;
cursor: pointer;
background: var(--primary-color);
color: #fff;
border: none;
border-radius: 5px;
}
.btn-outline {
background-color: transparent;
border: 1px #fff solid;
}
.btn:hover {
transform: scale(0.98);
}
/* Backgrounds & colored buttons */
.bg-primary,
.btn-primary {
background-color: var(--primary-color);
color: #fff;
}
.bg-secondary,
.btn-secondary {
background-color: var(--secondary-color);
color: #fff;
}
.bg-dark,
.btn-dark {
background-color: var(--dark-color);
color: #fff;
}
.bg-light,
.btn-light {
background-color: var(--light-color);
color: #333;
}
.bg-primary a,
.btn-primary a,
.bg-secondary a,
.btn-secondary a,
.bg-dark a,
.btn-dark a {
color: #fff;
}
/* Text colors */
.text-primary {
color: var(--primary-color);
}
.text-secondary {
color: var(--secondary-color);
}
.text-dark {
color: var(--dark-color);
}
.text-light {
color: var(--light-color);
}
/* Text sizes */
.lead {
font-size: 20px;
}
.sm {
font-size: 1rem;
}
.md {
font-size: 2rem;
}
.lg {
font-size: 3rem;
}
.xl {
font-size: 4rem;
}
.text-center {
text-align: center;
}
/* Alert */
.alert {
background-color: var(--light-color);
padding: 10px 20px;
font-weight: bold;
margin: 15px 0;
}
.alert i {
margin-right: 10px;
}
.alert-success {
background-color: var(--success-color);
color: #fff;
}
.alert-error {
background-color: var(--error-color);
color: #fff;
}
.flex {
display: flex;
justify-content: center;
align-items: center;
height: 100%;
}
.grid {
display: grid;
grid-template-columns: repeat(2, 1fr);
gap: 20px;
justify-content: center;
align-items: center;
height: 100%;
}
.grid-3 {
grid-template-columns: repeat(3, 1fr);
}
.sticky{
position: fixed;
top: 0;
width: 100%;
}
.cli .grid {
grid-template-columns: repeat(3, 1fr);
grid-template-rows: repeat(2, 1fr);
}
.cli .grid > *:first-child {
grid-column: 1 / span 2;
grid-row: 1 / span 2;
}
My answer is as advice.
Make it a rule to wrap all your content in the main div, like here:
<div class="main">
...
</div>
In my example, I used position: sticky.
In the css, I marked the edits.
anime.timeline({loop: true})
.add({
targets: '.ml5 .line',
opacity: [0.5,1],
scaleX: [0, 1],
easing: "easeInOutExpo",
duration: 700
}).add({
targets: '.ml5 .line',
duration: 600,
easing: "easeOutExpo",
translateY: (el, i) => (-0.625 + 0.625*2*i) + "em"
}).add({
targets: '.ml5 .ampersand',
opacity: [0,1],
scaleY: [0.5, 1],
easing: "easeOutExpo",
duration: 600,
offset: '-=600'
}).add({
targets: '.ml5 .letters-left',
opacity: [0,1],
translateX: ["0.5em", 0],
easing: "easeOutExpo",
duration: 600,
offset: '-=300'
}).add({
targets: '.ml5 .letters-right',
opacity: [0,1],
translateX: ["-0.5em", 0],
easing: "easeOutExpo",
duration: 600,
offset: '-=600'
}).add({
targets: '.ml5',
opacity: 0,
duration: 1000,
easing: "easeOutExpo",
delay: 1000
});
body {
box-sizing: border-box; /*add*/
margin: 0; /*add*/
padding: 0; /*add*/
}
.navbar {
background-color: var(--primary-color);
color: #fff;
min-height: 80px;
position: sticky;
top: 0;
z-index: 9999;
}
.navbar ul {
display: flex;
flex-direction: row;
flex-grow:1;
}
.navbar a {
color: #fff;
padding: 10px;
margin: 0 2px;
}
.navbar a:hover {
border-bottom: 2px #fff solid;
}
.navbar .flex {
justify-content:space-between;
}
.navbar .social a{
margin: 0 2px;
flex-grow:1;
}
.navbar .social > *:nth-child(3){
font-size: 28px;
}.showcase {
height: 400px;
background-color: var(--primary-color);
color: #fff;
position: relative;
}
.showcase h1 {
font-size: 40px;
}
.showcase p {
margin: 20px 0;
}
.showcase .grid {
overflow: visible;
grid-template-columns: 55% auto;
gap: 30px;
}
.showcase-text {
animation: slideInFromLeft 1s ease-in;
}
.showcase-form {
position: relative;
top: 60px;
height: 350px;
width: 400px;
padding: 40px;
z-index: 100;
justify-self: flex-end;
animation: slideInFromRight 1s ease-in;
}
.showcase-form .form-control {
margin: 30px 0;
}
.showcase-form input[type='text'],
.showcase-form input[type='email'] {
border: 0;
border-bottom: 1px solid #b4becb;
width: 100%;
padding: 3px;
font-size: 16px;
}
.showcase-form input:focus {
outline: none;
}
.showcase::before,
.showcase::after {
content: '';
position: absolute;
height: 100px;
bottom: -70px;
right: 0;
left: 0;
background: #fff;
transform: skewY(-3deg);
-webkit-transform: skewY(-3deg);
-moz-transform: skewY(-3deg);
-ms-transform: skewY(-3deg);
}
#import url('https://fonts.googleapis.com/css2?family=Lato:wght#300&display=swap');
:root {
--primary-color: #047aed;
--secondary-color: #1c3fa8;
--dark-color: #002240;
--light-color: #f4f4f4;
--success-color: #5cb85c;
--error-color: #d9534f;
}
* {
box-sizing: border-box;
padding: 0;
margin: 0;
}
body {
font-family: 'Lato', sans-serif;
color: #333;
line-height: 1.6;
}
ul {
list-style-type: none;
}
a {
text-decoration: none;
color: #333;
}
h1,
h2 {
font-weight: 300;
line-height: 1.2;
margin: 10px 0;
}
p {
margin: 10px 0;
}
img {
width: 100%;
}
code,
pre {
background: #333;
color: #fff;
padding: 10px;
}
.hidden {
visibility: hidden;
height: 0;
}
/* Features */
.features-head img,
.docs-head img {
width: 200px;
justify-self: flex-end;
}
.features-sub-head img {
width: 300px;
justify-self: flex-end;
}
.features-main .card > i {
margin-right: 20px;
}
.features-main .grid {
padding: 30px;
}
.features-main .grid > *:first-child {
grid-column: 1 / span 3;
}
.features-main .grid > *:nth-child(2) {
grid-column: 1 / span 2;
}
/* Docs */
.docs-main h3 {
margin: 20px 0;
}
.docs-main .grid {
grid-template-columns: 1fr 2fr;
align-items: flex-start;
}
.docs-main nav li {
font-size: 17px;
padding-bottom: 5px;
margin-bottom: 5px;
border-bottom: 1px #ccc solid;
}
.docs-main a:hover {
font-weight: bold;
}
/* Tablets and under */
#media (max-width: 768px) {
.grid,
.showcase .grid,
.stats .grid,
.cli .grid,
.cloud .grid,
.features-main .grid,
.docs-main .grid {
grid-template-columns: 1fr;
grid-template-rows: 1fr;
}
.showcase {
height: auto;
}
.showcase-text {
text-align: center;
margin-top: 40px;
animation: slideInFromTop 1s ease-in;
}
.showcase-form {
justify-self: center;
margin: auto;
animation: slideInFromBottom 1s ease-in;
}
.cli .grid > *:first-child {
grid-column: 1;
grid-row: 1;
}
.features-head,
.features-sub-head,
.docs-head {
text-align: center;
}
.features-head img,
.features-sub-head img,
.docs-head img {
justify-self: center;
}
.features-main .grid > *:first-child,
.features-main .grid > *:nth-child(2) {
grid-column: 1;
}
}
/* Mobile */
#media (max-width: 500px) {
.navbar {
height: 110px;
}
.navbar .flex {
flex-direction: column;
}
.navbar ul {
padding: 10px;
background-color: rgba(0, 0, 0, 0.1);
}
.showcase-form {
width: 300px;
}
}.container {
max-width: 1400px;
margin: 0 auto;
overflow: auto;
padding: 0 40px;
align-self: start;
}
.main {
min-height: 100vh; /*add*/
}
.card {
background-color: #fff;
color: #333;
border-radius: 10px;
box-shadow: 0 3px 10px rgba(0, 0, 0, 0.2);
padding: 20px;
margin: 10px;
}
.btn {
display: inline-block;
padding: 10px 30px;
cursor: pointer;
background: var(--primary-color);
color: #fff;
border: none;
border-radius: 5px;
}
.btn-outline {
background-color: transparent;
border: 1px #fff solid;
}
.btn:hover {
transform: scale(0.98);
}
/* Backgrounds & colored buttons */
.bg-primary,
.btn-primary {
background-color: var(--primary-color);
color: #fff;
}
.bg-secondary,
.btn-secondary {
background-color: var(--secondary-color);
color: #fff;
}
.bg-dark,
.btn-dark {
background-color: var(--dark-color);
color: #fff;
}
.bg-light,
.btn-light {
background-color: var(--light-color);
color: #333;
}
.bg-primary a,
.btn-primary a,
.bg-secondary a,
.btn-secondary a,
.bg-dark a,
.btn-dark a {
color: #fff;
}
/* Text colors */
.text-primary {
color: var(--primary-color);
}
.text-secondary {
color: var(--secondary-color);
}
.text-dark {
color: var(--dark-color);
}
.text-light {
color: var(--light-color);
}
/* Text sizes */
.lead {
font-size: 20px;
}
.sm {
font-size: 1rem;
}
.md {
font-size: 2rem;
}
.lg {
font-size: 3rem;
}
.xl {
font-size: 4rem;
}
.text-center {
text-align: center;
}
/* Alert */
.alert {
background-color: var(--light-color);
padding: 10px 20px;
font-weight: bold;
margin: 15px 0;
}
.alert i {
margin-right: 10px;
}
.alert-success {
background-color: var(--success-color);
color: #fff;
}
.alert-error {
background-color: var(--error-color);
color: #fff;
}
.flex {
display: flex;
justify-content: center;
align-items: center;
height: 100%;
}
.grid {
display: grid;
grid-template-columns: repeat(2, 1fr);
gap: 20px;
justify-content: center;
align-items: center;
height: 100%;
}
.grid-3 {
grid-template-columns: repeat(3, 1fr);
}
.sticky{
position: fixed;
top: 0;
width: 100%;
}
.cli .grid {
grid-template-columns: repeat(3, 1fr);
grid-template-rows: repeat(2, 1fr);
}
.cli .grid > *:first-child {
grid-column: 1 / span 2;
grid-row: 1 / span 2;
}
/*Animation h1*/
/*.ml5 {
position: relative;
font-weight: 300;
font-size: 4.5em;
color: #402d2d;
}*/
.ml5 .text-wrapper {
position: relative;
display: inline-block;
padding-top: 0.1em;
padding-right: 0.05em;
padding-bottom: 0.15em;
line-height: 1em;
}
.ml5 .line {
position: absolute;
left: 0;
top: 0;
bottom: 0;
margin: auto;
height: 3px;
width: 100%;
background-color: #FFFFFF;
transform-origin: 0.5 0;
}
.ml5 .ampersand {
font-family: Baskerville, serif;
font-style: italic;
font-weight: 400;
width: 1em;
margin-right: -0.1em;
margin-left: -0.1em;
}
.ml5 .letters {
display: inline-block;
opacity: 0;
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/animejs/2.0.2/anime.min.js"></script>
<div class="main">
<div class="navbar ">
<div class="container flex lead ">
<nav>
<ul>
<li>Acasa</li>
<li>Proiecte</li>
<li>Recenzii</li>
</ul>
</nav>
<div>
<h1 class="ml5">
<span class="text-wrapper">
<span class="line line1"></span>
<span class="letters letters-left">Carol</span>
<span class="letters ampersand">&</span>
<span class="letters letters-right">Housing</span>
<span class="line line2"></span>
</span>
</h1>
</div>
<div class="social sm">
<i class="fab fa-facebook fa-2x"></i>
<i class="fab fa-instagram fa-2x"></i>
Contact
</div>
</div>
</div>
<section class="showcase">
<div class="container grid">
<div class="showcase-text">
<h1>Easier Deployment</h1>
<p>Deploy web apps of all kinds, from large scale enterprise APIs to static websites for individuals. Fill out the form to try a demo of our platform</p>
Read More
</div>
<div class="showcase-form card">
<h2>Request a Demo</h2>
<form>
<div class="form-control">
<input type="text" name="name" placeholder="Name" required>
</div>
<div class="form-control">
<input type="text" name="company" placeholder="Company Name" required>
</div>
<div class="form-control">
<input type="email" name="email" placeholder="Email" required>
</div>
<input type="submit" value="Send" class="btn btn-primary">
</form>
</div>
</div>
</section>
<section class="cli">
<div class="container grid">
<img src="images/cli.png" alt="">
<div class="card">
<h3>Easy to use, cross platform CLI</h3>
</div>
<div class="card">
<h3>Deploy in seconds</h3>
</div>
</div>
</section>
<!-- Footer -->
<footer class="footer bg-dark py-5">
<div class="container grid grid-3">
<div>
<h1>Loruki
</h1>
<p>Copyright © 2020</p>
</div>
<nav>
<ul>
<li>Home</li>
<li>Features</li>
<li>Docs</li>
</ul>
</nav>
<div class="social">
<i class="fab fa-facebook fa-2x"></i>
<i class="fab fa-instagram fa-2x"></i>
</div>
</div>
</footer>
</div>
set the the height of container ( must be navbar parent though ) to 100vh and keep overflow: auto or set to overflow-y: scroll.
then set the position property on the navbar to 'sticky':
position: sticky
and enjoy! :)
Try doing this to the navigation container.
position: fixed;
Here is a code example.
<html>
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>A Great Demo on CodePen</title>
</head>
<body>
<nav>
<ul>
<li>Home</li>
<li>About</li>
<li>Works</li>
<li>Contact</li>
</ul>
</nav>
<div></div>
<div></div>
</body>
</html>
body {
margin: 0;
}
nav ul {
width: 100%;
margin: 0;
position: fixed;
display: flex;
background-color: green;
}
ul li {
list-style: none;
margin: 20px;
}
div {
height: 500px;
width: 500px;
background-color: red;
}

how to adjust padding in html/css?

I want to give padding on image to close to the remaining section but nothing works for me.
I am trying:
float-right or padding-right:250px; // but nothing happent and also it will spoil my mobile view also.
Kindly check what I am doing:
.fontProfile {
font-family: "Open Sans", Arial, sans-serif;
/* min-height: 100vh;
background-color: #fafafa;
color: #262626;
padding-bottom: 3rem; */
}
.imgProfile {
display: block;
}
.containerProfile {
max-width: 93.5rem;
margin: 0 auto;
padding: 0 2rem;
}
.btnProfileIn {
display: inline-block;
font: inherit;
background: none;
border: none;
color: inherit;
padding: 0;
cursor: pointer;
}
.btnProfileIn:focus {
outline: 0.5rem auto #4d90fe;
}
/* Profile Section */
.profile {
padding: 5rem 0;
}
.profile::after {
content: "";
display: block;
clear: both;
}
.profile-image {
float: left;
width: calc(33.333% - 1rem);
display: flex;
justify-content: center;
align-items: center;
margin-right: 3rem;
}
.imgProfile {
border-radius: 50%;
}
.profile-user-settings,
.profile-stats,
.profile-bio {
float: left;
width: calc(66.666% - 2rem);
}
.profile-user-settings {
margin-top: 1.1rem;
}
.profile-user-name {
display: inline-block;
font-size: 3.2rem;
font-weight: 300;
}
.profile-edit-btn {
font-size: 1.4rem;
line-height: 1.8;
border: 0.1rem solid #dbdbdb;
border-radius: 0.3rem;
padding: 0 2.4rem;
margin-left: 2rem;
}
.profile-settings-btn {
font-size: 2rem;
margin-left: 1rem;
}
.profile-stats {
margin-top: 2.3rem;
}
.profile-stats li {
display: inline-block;
font-size: 1.6rem;
line-height: 1.5;
margin-right: 4rem;
cursor: pointer;
}
.profile-stats li:last-of-type {
margin-right: 0;
}
.profile-bio {
font-size: 1.6rem;
font-weight: 400;
line-height: 1.5;
margin-top: 2.3rem;
}
.profile-real-name,
.profile-stat-count,
.profile-edit-btn {
font-weight: 600;
}
/* Media Query */
#media screen and (max-width: 40rem) {
.profile {
display: flex;
flex-wrap: wrap;
padding: 4rem 0;
}
.profile::after {
display: none;
}
.profile-image,
.profile-user-settings,
.profile-bio,
.profile-stats {
float: none;
width: auto;
}
.profile-image {
width: 3.7rem;
}
.profile-user-settings {
flex-basis: calc(100% - 10.7rem);
display: flex;
flex-wrap: wrap;
margin-top: 1rem;
}
.profile-user-name {
font-size: 2.2rem;
}
.profile-edit-btn {
order: 1;
padding: 0;
text-align: center;
margin-top: 1rem;
}
.profile-edit-btn {
margin-left: 0;
}
.profile-bio {
font-size: 1.4rem;
margin-top: 1.5rem;
}
.profile-edit-btn,
.profile-bio,
.profile-stats {
flex-basis: 100%;
}
.profile-stats {
order: 1;
margin-top: 1.5rem;
}
.profile-stats ul {
display: flex;
text-align: center;
padding: 1.2rem 0;
border-top: 0.1rem solid #dadada;
border-bottom: 0.1rem solid #dadada;
}
.profile-stats li {
font-size: 1.4rem;
flex: 1;
margin: 0;
}
.profile-stat-count {
display: block;
}
}
#supports (display: grid) {
.profile {
display: grid;
grid-template-columns: 1fr 2fr;
grid-template-rows: repeat(3, auto);
grid-column-gap: 3rem;
align-items: center;
}
.profile-image {
grid-row: 1 / -1;
}
.profile-image,
.profile-user-settings,
.profile-stats,
.profile-bio {
width: auto;
margin: 0;
}
#media (max-width: 40rem) {
.profile {
grid-template-columns: auto 1fr;
grid-row-gap: 1.5rem;
}
.profile-image {
grid-row: 1 / 2;
}
.profile-user-settings {
display: grid;
grid-template-columns: auto 1fr;
grid-gap: 1rem;
}
.profile-edit-btn,
.profile-stats,
.profile-bio {
grid-column: 1 / -1;
}
.profile-user-settings,
.profile-edit-btn,
.profile-settings-btn,
.profile-bio,
.profile-stats {
margin: 0;
}
}
}
<header>
<div class="container containerProfile">
<div class="profile">
<div class="profile-image">
<img class="imgProfile" src="https://images.unsplash.com/photo-1513721032312-6a18a42c8763?w=152&h=152&fit=crop&crop=faces" alt="">
</div>
<div class="profile-user-settings">
<h1 class="profile-user-name fontProfile">janedoe_</h1>
<button class="btnProfileIn profile-edit-btn">Edit Profile</button>
<button class="btnProfileIn profile-settings-btn" aria-label="profile settings"><i class="fa fa-cog" aria-hidden="true"></i></button>
</div>
<div class="profile-stats">
<ul>
<li><span class="profile-stat-count">164</span> posts</li>
<li><span class="profile-stat-count">188</span> followers</li>
<li><span class="profile-stat-count">206</span> following</li>
</ul>
</div>
<div class="profile-bio">
<!-- <p><span class="profile-real-name">Jane Doe</span></p> -->
</div>
</div>
<!-- End of profile section -->
</div>
<!-- End of container -->
</header>
I am having so much gap between Image and name. I want that div come close to the remaining part.
This is the problem - The gap
Any idea or suggestions would be welcome.
try on your css part
.imgProfile {
padding-right:250px }
Instead of adding padding to the profile-image what you can do is to try to make the remaining part come close to the image div and for this you can do this:
.profile-user-settings {
width: auto;
margin: 0px;
margin-right: -35px;
}
You can use flex for the image div and justify the content to the end.
.imgProfile {
display: flex;
justify-content: flex-end;
}
If you include margin-left:200px(or whatever you want), you can close the pic to the remaining section.Like this:
.imgProfile { display: block; margin-left: 200px; }
in this part of the
css
`#supports (display: grid){ .profile {
display: grid;
grid-template-columns: auto 1fr;
grid-template-rows: repeat(3, auto);
grid-column-gap: 3rem;
align-items: center;}`
change like i did grid-template-columns:1fr 2fr; to auto 1fr ; and you can remove grid-column-gap