How to make an image slide down - html

I would like to make the image in the center of the navigation bar slide down when the width of the page decreases.
This is how it looks like on a desktop:
Whereas on a smartphone the navigation bar should look like this:
As you can see, I would like the nav bar to remain as it is, except for the image to slide down the first row.
body {
background-color: gray;
color: white;
font-family: Helvetica Neue;
}
/* Header */
header {
background-color: black;
background-image: url("images/spiaggia.jpg");
background-size: 100%;
background-position: center;
padding: 2px;
color: white;
height: 200px;
background-repeat: no-repeat
}
section {
background-color: white;
color: gray;
padding: 20px;
display: flex;
flex-direction: row;
}
div {
background-color: black;
display: inline-block;
width: 100px;
margin: auto;
color: white;
}
header ul {
margin: 0px;
padding: 0px;
}
header li {
text-decoration: none;
display: inline-block;
margin-right: 20px;
}
header .mobile {
display: none;
}
a {
color: white;
text-decoration: none;
}
.logo {
background-image: url("images/città.jpg");
background-size: 100px;
background-repeat: no-repeat;
display: inline-block;
height: 50px;
position: relative;
text-indent: -999999px;
top: 0px;
width: 100px;
border: solid lightblue;
}
/* Features */
.features {
background: white;
color: gray;
padding: 20px;
display: flex;
flex-direction: row;
}
.features figure {
margin: auto;
text-align: center;
text-transform: uppercase;
width: 200px;
}
.features figure img {
border: 1px solid white;
border-radius: 10%;
box-shadow: gray 0 0 10px;
width: 200px;
}
/* Footer */
footer {
background: black;
padding: 10px 20px;
color: gray;
font-size: 12px;
padding: 20px 20px;
text-align: center;
}
#media (max-width: 600px) {
.mobile {
display: inline-block;
}
.desktop {
display: none;
}
}
<header>
<ul>
<li>Home</li>
<li>Menu</li>
<li><a class="logo" href="Home.html">Cadice_foto</a></li>
<li class="mobile">Locations</li>
<li class="mobile">Contacts</li>
<li class="desktop">Locations</li>
<li class="desktop">Contacts</li>
</ul>
</header>
<section class="features">
<figure>
<img src="images/porticciolo.jpg" alt="porticciolo Cadice">
<figcaption>Porticciolo Cadice</figcaption>
</figure>
<figure>
<img src="images/palme.jpg" alt="palme Cadice">
<figcaption>palme Cadice</figcaption>
</figure>
<figure>
<img src="images/sera.jpg" alt="sera Cadice">
<figcaption>sera Cadice</figcaption>
</figure>
</section>
<section>lower-section</section>
<footer>Via Condotti, Roma IT - numero: 02.123456 - email#email.com</footer>

This can be done with a css flex-box, and re-ordering the flex elements when your mobile view media query activates.
.menu-container {
display: flex;
flex-flow: row wrap;
text-align: center;
}
.menu-container>* {
padding: 10px;
flex: 1 20%;
}
#media all and (min-width: 600px) {
.menu-container>* {
flex: 1;
counter-increment: menulink;
order: counter(menulink);
}
.menu-left {
order: 1
}
.menu-right {
order: 3
}
.logo-menu {
order: 2;
}
}
body {
background-color: gray;
color: white;
font-family: Helvetica Neue;
}
/* Header */
header {
background-color: black;
background-image: url("http://placekitten.com/1000/500?image=6");
background-size: 100%;
background-position: center;
padding: 2px;
color: white;
height: 200px;
background-repeat: no-repeat
}
section {
background-color: white;
color: gray;
padding: 20px;
display: flex;
flex-direction: row;
}
a {
color: white;
text-decoration: none;
}
.logo {
background-image: url("http://placekitten.com/200/100");
background-size: 100px;
background-repeat: no-repeat;
display: inline-block;
height: 50px;
position: relative;
text-indent: -999999px;
top: 0px;
width: 100px;
border: solid lightblue;
}
/* Features */
.features {
background: white;
color: gray;
padding: 20px;
display: flex;
flex-direction: row;
}
.features figure {
margin: auto;
text-align: center;
text-transform: uppercase;
width: 200px;
}
.features figure img {
border: 1px solid white;
border-radius: 10%;
box-shadow: gray 0 0 10px;
width: 200px;
}
/* Footer */
footer {
background: black;
padding: 10px 20px;
color: gray;
font-size: 12px;
padding: 20px 20px;
text-align: center;
}
.menu-container {
display: flex;
flex-flow: row wrap;
text-align: center;
}
.menu-container>* {
padding: 10px;
flex: 1 20%;
}
#media all and (min-width: 600px) {
.menu-container>* {
flex: 1;
counter-increment: menulink;
order: counter(menulink);
}
.menu-left {
order: 1
}
.menu-right {
order: 3
}
.logo-menu {
order: 2;
}
}
<!DOCTYPE html>
<html>
<head>
<title></title>
<link rel="stylesheet" href="11.css" type="text/css" />
</head>
<body>
<header class="menu-container">
<a class="menu-left" href="Home.html">Home</a>
<a class="menu-left" href="website/Menu.html">Menu</a>
<a class="menu-right"href="website/Locations.html">Locations</a>
<a class="menu-right" href="website/Contacts.html">Contacts</a>
<div class="logo-menu"><a class="logo" href="Home.html">Cadice_foto</a></div>
</header>
<section class="features">
<figure>
<img src="http://placekitten.com/150/150?image=2" alt="porticciolo Cadice">
<figcaption>Porticciolo Cadice</figcaption>
</figure>
<figure>
<img src="http://placekitten.com/150/150?image=8" alt="palme Cadice">
<figcaption>palme Cadice</figcaption>
</figure>
<figure>
<img src="http://placekitten.com/150/150?image=4" alt="sera Cadice">
<figcaption>sera Cadice</figcaption>
</figure>
</section>
<section>lower-section</section>
<footer>Via Lars, somewhere IT - numero: uno!- email#email.com</footer>
</body>
</html>

Add the following in media query below in your CSS:
.logo {
position: absolute;
top: 50px;
left: 0;
right: 0;
margin: 0 auto;
}
You may want to know what this code does. The position property specifies the type of positioning used for an element. The top property is the vertical position of a positioned element. The left and the right properties are written to reset positioning (these are "auto" by default), and then margin which is "0 auto" to align element by center. https://www.w3schools.com/css/css_margin.asp
You should probably see some info about media-queries here: https://developer.mozilla.org/en-US/docs/Web/CSS/Media_Queries/Using_media_queries
P.S. And remember DRY (Do not Repeat Yourself). Try to avoid writing twice, especially something like this:
<li class="mobile">Locations</li>
<li class="mobile">Contacts</li>
<li class="desktop">Locations</li>
<li class="desktop">Contacts</li>
You can set every property for every element in every media-query

I have changed your code little bit to achieve what you wanted. Here is the Code
body {
background-color: gray;
color: white;
font-family: Helvetica Neue;
}
/* Header */
header {
background-color: black;
background-image: url("https://www.hotelsantamargherita.it/wp-content/uploads/2017/12/caorle-dalla-spiaggia-di-pon-1440x500.jpg");
background-size: 100%;
background-position: center;
padding: 2px;
color: white;
height: 200px;
background-repeat: no-repeat;
}
section {
background-color: white;
color: gray;
padding: 20px;
display: flex;
flex-direction: row;
}
div {
background-color: black;
display: inline-block;
width: 100px;
margin: auto;
color: white;
}
.navbar {
margin: 0px;
padding: 0px;
text-align: center;
position: relative;
}
.navbar li {
text-decoration: none;
display: inline-block;
margin-right: 20px;
}
.navbar li a {
color: white;
text-decoration: none;
}
.logo a {
background-image: url("http://www.florenceholidays.com/image/66-05.jpg");
background-size: 100px;
background-repeat: no-repeat;
display: inline-block;
height: 50px;
position: relative;
text-indent: -9999px;
top: 0px;
width: 100px;
border: solid lightblue;
}
/* Features */
.features {
background: white;
color: gray;
padding: 20px;
display: flex;
flex-direction: row;
}
.features figure {
margin: auto;
text-align: center;
text-transform: uppercase;
width: 200px;
}
.features figure img {
border: 1px solid white;
border-radius: 10%;
box-shadow: gray 0 0 10px;
width: 200px;
}
/* Footer */
footer {
background: black;
padding: 10px 20px;
color: gray;
font-size: 12px;
padding: 20px 20px;
text-align: center;
}
#media (max-width: 600px) {
.logo {
position: absolute;
top: 50px;
left: 50%;
transform: translatex(-50%)
}
}
<header>
<ul class="navbar">
<li>Home</li>
<li>Menu</li>
<li class="logo">Cadice_foto</li>
<li>Locations</li>
<li>Contacts</li>
<!-- <li class="desktop">Locations</li>
<li class="desktop">Contacts</li> -->
</ul>
</header>
<section class="features">
<figure>
<img src="https://picsum.photos/200/300" alt="porticciolo Cadice">
<figcaption>Porticciolo Cadice</figcaption>
</figure>
<figure>
<img src="https://picsum.photos/200/300" alt="palme Cadice">
<figcaption>palme Cadice</figcaption>
</figure>
<figure>
<img src="https://picsum.photos/200/300" alt="sera Cadice">
<figcaption>sera Cadice</figcaption>
</figure>
</section>
<section>lower-section</section>
<footer>Via Condotti, Roma IT - numero: 02.123456 - email#email.com</footer>

Related

divs appear above the footer instead of inside the footer

I am just practicing CSS/HTML and am trying to make a google clone. Everything else seems fine but now I am trying to make a footer and whenever I put a div inside the footer, they appear on top of the footer instead of inside the footer.
#import url('https://fonts.googleapis.com/css2?family=Roboto:wght#300;400;700&display=swap');
* {
margin: 0;
padding: 0;
box-sizing: border-box;
font-family: 'Roboto', sans-serif;
background-color: rgb(32, 33, 36);
color: white;
}
a {
text-decoration: none;
color: inherit;
}
.nav-bar a:nth-child(1):hover {
text-decoration: underline;
}
.nav-bar a:nth-child(2):hover {
text-decoration: underline;
}
.nav-bar {
height: 50px;
display: flex;
align-items: center;
justify-content: flex-end;
}
.nav-items {
list-style: none;
display: flex;
justify-content: flex-end;
align-items: center;
}
.nav-items li {
margin-left: 15px;
}
.menu-icon {
display: flex;
flex-direction: column;
align-items: center;
justify-content: space-around;
width: 40px;
height: 40px;
padding: 10px;
border-radius: 50%;
}
.menu-icon:hover {
background-color: rgba(138, 133, 133, 0.26);
}
.menu-icon span {
background-color: #ffffff;
width: 20px;
height: 2px;
}
.profile-picture {
margin-right: 15px;
height: 32px;
width: 32px;
border-radius: 50%;
}
.profile-picture:hover {
box-shadow: 0px 0px 0px 5px #7068683b;
}
.profile-picture img {
border-radius: 50%;
width: 100%;
}
.main-section {
display: flex;
justify-content: center;
align-items: center;
margin-top: 80px;
}
.google-logo {
width: 375px;
height: 150px;
}
.google-logo img {
width: 100%;
}
.search-section {
display: flex;
justify-content: center;
align-items: center;
flex-direction: column;
}
.search-container {
display: flex;
justify-content: center;
align-items: center;
width: 580px;
border: solid;
border-color: #949090;
border-width: 1px;
border-radius: 300px;
padding: 9px;
height: 45px;
}
.search-container:hover {
box-shadow: 0px 0px 10px 2px #00000036;
}
.search-icon {
width: 25px;
height: 25px;
margin-right: 5px;
}
.search-icon img {
width: 100%;
}
.search-bar {
width: 550px;
height: 30px;
border: none;
outline: none;
}
.microphone {
width: 25px;
height: 25px;
}
.microphone img {
width: 100%;
}
.search-buttons {
margin-top: 25px;
}
.search-buttons button {
margin-left: 6px;
padding: 10px 16px 10px 16px;
background-color: #303134;
border: none;
border-radius: 4px;
color: #e8eaed;
font-size: 14px;
cursor: pointer;
border: solid 1px transparent;
}
.search-buttons button:hover {
border-color: #e8eaed;
}
.language-selector {
display: flex;
justify-content: center;
margin-top: 30px;
}
.language-selector p {
font-size: 13px;
color: #bdc1c6;
}
.language-selector a {
color: #8ab4f8;
}
.footer {
background-color: #446adb;
height: 100px;
margin-top: 92px;
}
<body>
<!-- start of the navigation bar-->
<nav class="nav-bar">
<ul class="nav-items">
<li>Gmail</li>
<li>სურათები</li>
<li>
<a href="#">
<div class="menu-icon">
<span>
</span>
<span>
</span>
<span>
</span>
</div>
</a>
</li>
<li>
<a href="#"><div class="profile-picture">
<img src="icons/unnamed.png">
</div></a>
</li>
</ul>
</nav>
<!-- end of the navigation bar -->
<!-- start of the main section (logo and search-bar)-->
<div class="main-section">
<a href="#"><div class="google-logo">
<img src="icons/google.png">
</div></a>
</div>
<div class="search-section">
<div class="search-container">
<div class="search-icon"><img src="icons/search.png"/></div>
<input type="text" class="search-bar">
<div class="microphone"><img src="icons/micro.png" alt=""></div>
</div>
<div class="search-buttons">
<button>
Google ძებნა
</button>
<button>
იღბალს მივენდობი
</button>
</div>
</div>
<div class="language-selector">
<p>Google ხელმისაწვდომია შემდეგ ენაზე: English</p>
</div>
<!-- end of the main section -->
<!-- start of the footer-->
<footer class="footer">
<div class="current-location">
this text should be inside the footer
</div>
</footer>
</body>
here is the picture of the problem I am having.
https://i.stack.imgur.com/AXMv6.png
It is inside the footer. Just this property:
background-color: rgb(32, 33, 36);
which you set for * gets inherited, and the bg color makes you think text it outside the footer. Comment it out for a while and you will see.

Navbar pushes DIV's off screen

The purple Navbar at the top of the page pushes the container "container2" off screen. Is there any possible way I can make it so the "container2" div does not overflow with the proper padding of 5px at the bottom?
#import url('https://fonts.googleapis.com/css2?family=Gugi&display=swap');
/*QuickReset*/ * { box-sizing: border-box; margin: 0; }
html {
height: 100%;
width: 100%
}
body {
background: black;
height: 100%;
position: relative;
overflow: hidden;
}
.navbar {
background: purple;
padding: 1em;
width: 100%;
position: relative;
top: 0;
}
.navbar .logo {
text-decoration: none;
font-family: 'Gugi', cursive;
font-weight: bold;
font-size: 1.5em;
color: white;
}
.navbar .container {
display: grid;
grid-template-columns: 100px auto;
justify-content: unset;
}
.navbar nav {
display: flex;
justify-content: space-between;
background: none;
position: unset;
height: auto;
width: 100%;
padding: 0;
}
.container2 {
display: flex;
width: 100%;
height: 100%;
position: relative;
gap: 5px;
padding: 5px;
}
.one,
.two {
border: 3px solid green;
border-radius: 5px;
}
.one { width: 10%; background: red; }
.two { width: 90%; background: blue; }
<div class="navbar">
<div class="container">
<a class="logo" href="#">Logo</a>
</div>
</div>
<div class="container2">
<div class="one">
</div>
<div class="two">
</div>
</div>
Resulting Page
I am new to HTML and CSS so any helps greatly appreciated.
Stack overflow wants more content besides code but im not too sure what else to add.
Remove overflow: hidden from body:
#import url('https://fonts.googleapis.com/css2?family=Gugi&display=swap');
/*QuickReset*/
* {
box-sizing: border-box;
margin: 0;
}
html {
height: 100%;
width: 100%
}
body {
background: black;
height: 100%;
position: relative;
/*overflow: hidden;*/
}
.navbar {
background: purple;
padding: 1em;
width: 100%;
position: relative;
top: 0;
}
.navbar .logo {
text-decoration: none;
font-family: 'Gugi', cursive;
font-weight: bold;
font-size: 1.5em;
color: white;
}
.navbar .container {
display: grid;
grid-template-columns: 100px auto;
justify-content: unset;
}
.navbar nav {
display: flex;
justify-content: space-between;
background: none;
position: unset;
height: auto;
width: 100%;
padding: 0;
}
.container2 {
display: flex;
width: 100%;
height: 100%;
position: relative;
gap: 5px;
padding: 5px;
}
.one,
.two {
border: 3px solid green;
border-radius: 5px;
}
.one {
width: 10%;
background: red;
}
.two {
width: 90%;
background: blue;
}
<div class="navbar">
<div class="container">
<a class="logo" href="#">Logo</a>
</div>
</div>
<div class="container2">
<div class="one">
</div>
<div class="two">
</div>
</div>
#import url('https://fonts.googleapis.com/css2?family=Gugi&display=swap');
/*QuickReset*/ * { box-sizing: border-box; margin: 0; }
body {
background: black;
height: 100vh;
position: relative;
overflow: hidden;
}
.navbar {
background: purple;
padding: 1em;
width: 100%;
position: relative;
top: 0;
height: 20%;
}
.navbar .logo {
text-decoration: none;
font-family: 'Gugi', cursive;
font-weight: bold;
font-size: 1.5em;
color: white;
}
.navbar .container {
display: grid;
grid-template-columns: 100px auto;
justify-content: unset;
}
.navbar nav {
display: flex;
justify-content: space-between;
background: none;
position: unset;
height: auto;
width: 100%;
padding: 0;
}
.container2 {
display: flex;
width: 100%;
height: 80%;
position: relative;
gap: 5px;
padding: 5px;
}
.one,
.two {
border: 3px solid green;
border-radius: 5px;
}
.one { width: 10%; background: red; }
.two { width: 90%; background: blue; }
<div class="navbar">
<div class="container">
<a class="logo" href="#">Logo</a>
</div>
</div>
<div class="container2">
<div class="one">
</div>
<div class="two">
</div>
</div>
you should divide the height of navbar and container 2

Divs not occupying 100% screen width

I have been developing a product landing page to practice & enhance my skills in responsive web designs. Here is what I have achieved so far. https://jsfiddle.net/Ghazi360/qj8zLp16/1/
I am having issues with the width of my divs. I can not figure out why are they not occupying full screen width & leaving a white empty border on the right side like this:
I have set
* {
box-sizing: border-box
}
& the width of Container div is also set to 100%. Kindly help me out with this. I hope I have been able to explain my problem.
Just do an overflow:hidden; on Container and you are good to go.
Note: These bugs are a bit difficult to catch. Always start debugging in developer window first ( A small tip)
CODEPEN LINK: https://codepen.io/emmeiWhite/pen/dypQqYz
#Container {
width: 100%;
background-color: #f5f5f5;
overflow: hidden; /*Add this */
}
FULL CODE:
* {
margin: 0;
padding: 0;
box-sizing: border-box;
}
body {
margin: 0;
padding: 0;
width: 100%;
}
#Container {
width: 100%;
background-color: #f5f5f5;
overflow:hidden;
}
#header {
width: 100%;
height: 50px;
background-color: red;
display: grid;
grid-template-columns: 30% 70%;
grid-gap: 10px;
position: fixed;
}
#headerImg {
width: 100%;
height: 50px;
background-image: url("https://freesvg.org/img/optical.png");
background-position: center;
background-repeat: no-repeat;
background-size: contain;
}
#header-img {
display: none;
}
#nav-bar {
width: 100%;
height: 50px;
background-color: rgb(126, 126, 31);
text-align: center;
display: flex;
justify-content: space-evenly;
align-items: center;
}
.nav-link {
font-size: 18px;
font-family: poppins;
text-decoration: none;
color: white;
border-bottom: 2px solid black;
}
.nav-link:hover {
transition: .8s;
color: black;
border-bottom: 2px solid white;
}
#About {
width: 100%;
height: 300px;
background-color: chocolate;
display: flex;
flex-direction: row;
flex-wrap: wrap;
}
#About h1 {
font-size: 42px;
font-family: poppins;
margin-top: 40px;
padding: 5px;
}
#About p {
font-size: 18px;
font-family: poppins;
padding: 10px;
}
#media only screen and (max-width: 425px) {
.nav-link {
font-size: 12px;
}
#About {
height: 430px;
}
#About h1 {
font-size: 32px;
}
#About p {
font-size: 14px;
}
}
#Features {
width: 100%;
height: 500px;
background-color: brown;
display: flex;
flex-direction: row;
flex-wrap: wrap;
}
.grid {
width: 100%;
height: 150px;
display: grid;
grid-template-columns: 25% 75%;
grid-gap: 10px;
}
.premiumIcon {
width: 82px;
background-image: url("https://www.flaticon.com/svg/vstatic/svg/2997/2997131.svg?token=exp=1610648143~hmac=0e319e924a0a195adb6360e2ea9596c8");
background-position: center;
background-repeat: no-repeat;
background-size: contain;
margin: 0 auto;
}
.fastIcon {
width: 82px;
background-image: url("https://www.flaticon.com/svg/vstatic/svg/1792/1792671.svg?token=exp=1610648298~hmac=ae66efe447d060ac530f58333ef179f6");
background-position: center;
background-repeat: no-repeat;
background-size: contain;
margin: 0 auto;
}
.qualityIcon {
width: 82px;
background-image: url("https://www.flaticon.com/svg/vstatic/svg/2649/2649798.svg?token=exp=1610646201~hmac=12c57329928c0f4774f73b68b9359a54");
background-position: center;
background-repeat: no-repeat;
background-size: contain;
margin: 0 auto;
}
.desc {
padding: 15px 5px 0px 5px;
}
.desc h2 {
font-size: 22px;
font-family: poppins;
padding: 10px;
}
.desc p {
font-size: 14px;
font-family: poppins;
padding: 10px;
}
#media only screen and (max-width: 425px) {
#Features {
height: 500px;
}
.grid {
height: 100px;
}
.premiumIcon,
.fastIcon,
.qualityIcon {
width: 52px;
}
.desc {
padding: 0;
}
.desc h2 {
font-size: 16px;
}
.desc p {
font-size: 12px;
}
}
#Video {
width: 100%;
height: 400px;
background-color: chartreuse;
display: flex;
justify-content: center;
align-items: center;
}
#Video iframe {
max-width: 560px;
}
#Products {
width: 100%;
height: 300px;
background-color: darkorchid;
display: flex;
align-items: center;
justify-content: space-evenly;
flex-direction: row;
flex-wrap: wrap;
}
#media only screen and (max-width: 425px) {
#Products {
height: 700px;
}
}
.card {
max-width: 200px;
height: 215px;
background: rgb(163, 86, 86);
display: flex;
flex-direction: column;
box-shadow: 0 5px 20px rgba(0, 0, 0, 0.5);
transition: 0.3s ease-in-out;
}
.imgBx {
width: 200px;
height: 215px;
}
.img1 {
background-image: url("https://images.unsplash.com/photo-1473496169904-658ba7c44d8a?ixid=MXwxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHw%3D&ixlib=rb-1.2.1&auto=format&fit=crop&w=750&q=80");
background-position: center;
background-repeat: no-repeat;
background-size: cover;
}
.img2 {
background-image: url("https://images.unsplash.com/photo-1509695507497-903c140c43b0?ixid=MXwxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHw%3D&ixlib=rb-1.2.1&auto=format&fit=crop&w=752&q=80");
background-position: center;
background-repeat: no-repeat;
background-size: cover;
}
.img3 {
background-image: url("https://lh3.googleusercontent.com/proxy/3lUUwuh-2MSiNDoxUeLIhenDfsd5c5OXJ71uG16L8_ciXyQG-9tKphBYpx4Z6oHqiWQWP_i7tvbvlX0DABn6jv6xsUkEvEOIdbStL22RSV9AFqBzHi2Dqnpi05_h8kmqWqLacaWDv5_lWpVvsVQ");
background-position: center;
background-repeat: no-repeat;
background-size: cover;
}
.card:hover {
height: 250px;
}
.card .content {
position: relative;
margin-top: -140px;
padding: 10px 15px;
text-align: center;
color: #111;
visibility: hidden;
opacity: 0;
transition: 0.3s ease-in-out;
}
.card:hover .content {
visibility: visible;
opacity: 1;
margin-top: -10px;
transition-delay: 0.3s;
}
.content h2 {
color: black;
font-size:30px;
font-family: poppins;
}
#form {
width: 100%;
height: 200px;
background-color: dodgerblue;
display: flex;
justify-content: center;
align-items: center;
flex-direction: column;
flex-wrap: wrap;
}
#form h2 {
font-family: poppins;
padding-bottom: 30px;
text-align: center;
}
#email {
width: 50%;
height: 50px;
border-radius: 30px;
padding-left: 10px;
border: none;
outline: none;
font-size: 18px;
font-family: poppins;
box-sizing: border-box;
}
#submit {
width: 100px;
height: 40px;
margin-top: 10px;
font-size: 20px;
font-family: poppins;
border: none;
border-radius: 6px;
outline: none;
cursor: pointer;
text-align: center;
}
#media only screen and (max-width: 425px) {
#form {
height: 300px;
}
#email {
width: 250px;
}
}
#footer {
margin-top: 30px;
background-color: #ddd;
padding: 20px;
}
#footer ul {
display: flex;
justify-content: flex-end;
list-style: none;
}
#footer li {
padding: 0 10px;
}
#footer a {
font-size: 14px;
font-family: poppins;
color: #000;
text-decoration: none;
}
#footer span {
margin-top: 5px;
display: flex;
justify-content: flex-end;
font-size: 0.9em;
color: #444;
font-size: 14px;
font-family: poppins;
}
<div id="Container">
<header id="header">
<div id="headerImg">
<img id="header-img" src="https://freesvg.org/img/optical.png" alt="Logo" id="header-img">
</div>
<nav id="nav-bar">
<a class="nav-link" href="#About">About</a>
<a class="nav-link" href="#Features">Features</a>
<a class="nav-link" href="#Products">Pricing</a>
</nav>
</header>
<div id="About">
<h1>Ghazi Eyewear</h1>
<p> Pakistan's Leading Online Sunglasses Shop Established 2004
Ghazi Eyewear stands out for its exclusive eyewear, glamorous frames
and colors to match your confidence.
Ghazi Eyewear provide you with the most complete eye care possible.
In our online store, you can choose from an excellent selection of
named brands. Ghazi Eyewear is offering
exceptional range of Men's Original Sunglasses at amazing
prices in Pakistan, accompanied with free home delivery to your
door step. We guarantee for providing best and reliable perfect frames.
We also provide the best prescription eyewear.
</p>
</div>
<div id="Features">
<div class="grid">
<div class="premiumIcon"></div>
<div class="desc">
<h2>Premium Materials</h2>
<p> Our frames use the finest material which is sourced locally.
This will increase the longevity of your purchase.
</p>
</div>
</div>
<div class="grid">
<div class="fastIcon"></div>
<div class="desc">
<h2>Fast Shipping</h2>
<p> We make sure you recieve your glasses as soon as we have finished
making it. We also provide free returns if you are not satisfied.
</p>
</div>
</div>
<div class="grid">
<div class="qualityIcon"></div>
<div class="desc">
<h2>Quality Assurance</h2>
<p> For every purchase you make, we will ensure there are no damages or
faults and we will check and test the quality of your purchase.
</p>
</div>
</div>
</div>
<div id="Video">
<iframe id="video" height="315px" width="560px" src="https://www.youtube.com/embed/wwM9mnw4v4s" allowfullscreen="true"></iframe>
</div>
<div id="Products">
<div class="card">
<div class="imgBx img1"></div>
<div class="content">
<h2>Men Sunglasses</h2>
</div>
</div>
<div class="card">
<div class="imgBx img2"></div>
<div class="content">
<h2>Women Sunglasses</h2>
</div>
</div>
<div class="card">
<div class="imgBx img3"></div>
<div class="content">
<h2>Eye Care Products</h2>
</div>
</div>
</div>
<form id="form" action="https://www.freecodecamp.com/email-submit">
<h2>Subscribe to our Newsletter!</h2>
<input name="email" id="email" type="email" placeholder="Enter your email" required>
<input name="submit" id="submit" type="submit" value="subscribe">
</form>
<footer id="footer">
<ul>
<li>Privacy</li>
<li>Terms</li>
<li>Contact</li>
</ul>
<span>Copyright 2021, Ghazi 360</span>
</footer>
</div>
What is causing the overflow is the grid-gap property in #header and .grid, they are not counted towards the percentage values you've added, you should remove that and use padding to create the desired spacing.
Edit:
#header {
width: 100%;
height: 50px;
background-color: red;
display: grid;
grid-template-columns: 30% 70%;
/* grid-gap: 10px; remove this */
position: fixed;
}
.grid {
width: 100%;
height: 150px;
display: grid;
grid-template-columns: 25% 75%;
/* grid-gap: 10px; and this */
}
Edit 2:
Alternatively you can also use the fr unit to occupy the remaining space and still use the grid-gap property:
#header {
width: 100%;
height: 50px;
background-color: red;
display: grid;
grid-template-columns: 30% 1fr; /* 1fr will be 70% - 10px */
grid-gap: 10px;
position: fixed;
}
.grid {
width: 100%;
height: 150px;
display: grid;
grid-template-columns: 25% 1fr; /* 1fr will be 75% - 10px */
grid-gap: 10px;
}
Others have pointed out that your grid doesn't take the grid-gap in to a count.
But the real issue to fix is that I found out your grid-template inside Features div that the one doesn't count the grid-gap.
If you still want to keep the grid-gap try lower the value of grid-template-columns to be 23% 75% respectively. So you allow that 10px from the grid-gap to take space.
.grid {
width: 100%;
height: 150px;
display: grid;
grid-template-columns: 23% 75%;
grid-gap: 10px;
}
Adjust the value as you see fit of course and make sure you take count of the grid-gap.

Site doesn't fit the viewport

I am running into some issues with resizing of the window (shrinking). When I shrink it down, the background colors no longer stay at the edge of the viewport, and content goes beyond it.
I thought that setting the width on the entire body to 100% would fix that, but it didn't?
Here is a JSFiddle of my current code, for the index page and the stylesheet:
* {
margin: 0;
padding: 0;
}
body {
font-family: Segoe UI, helvetica, arial;
display: flex;
flex-direction: column;
min-height: 100vh;
font-size: 18px;
width: 100%;
}
a {
color: hsl(344, 69%, 70%);
font-weight: bold;
}
a:hover {
text-decoration: none;
color: #67c3b2;
}
.menu-container {
background-color: rgba(150, 150, 150, 0.2);
padding: 20px 0;
display: flex;
justify-content: center;
text-transform: uppercase;
width: 100%;
}
.menu {
width: 90%;
display: flex;
top: 10px;
justify-content: space-between;
font-size: 16px;
overflow: hidden;
position: relative;
left: 10px;
}
.header-container {
background-color: rgba(150, 150, 150, 0.2);
display: flex;
justify-content: center;
height: 30px;
width: 100%;
position: relative;
}
.logo {
position: relative;
bottom: 37px;
z-index: 1;
}
.flex-container {
display: flex;
justify-content: center;
}
.flex-container p {
position: relative;
margin-left: 40px;
margin-right: 40px;
font-weight: bold;
top: 40px;
margin-top: 40px;
text-align: center;
}
.main {
display: flex;
color: #464646;
background: linear-gradient(to right, #77C9D4, #57BC90);
flex: 1;
}
.cakelist {
position: relative;
bottom: 50px;
display: flex;
font-weight: bold;
list-style-position: inside;
margin-top: 130px;
}
.cakelist ol,
table {
margin-left: 25px;
}
.cakelist h2 {
margin-left: 25px;
margin-top: 20px;
}
.carousel {
color: #464646;
top: 80px;
position: relative;
display: flex;
justify-content: center;
border: 3px outset gray;
align-items: center;
padding: 60px 60px 60px 60px;
}
.buttons {
position: relative;
width: 1600px;
margin-right: 25px;
justify-content: space-around;
display: flex;
top: 160px;
text-align: center;
}
.button a:hover {
opacity: 0.2;
}
.buttons p {
margin-top: 20px;
}
.buttons img {
padding-top: 25px;
height: 200px;
}
.gallery {
position: relative;
top: 80px;
}
.pricing {
display: flex;
position: relative;
top: 80px;
justify-content: center;
flex-direction: column;
padding-bottom: 140px;
}
.pricing p,
h1 {
margin-left: 250px;
text-align: left;
margin-top: 5px;
}
.pricing span {
opacity: 0;
user-select: none;
}
.order {
position: relative;
border-radius: 5px;
background: hsl(344, 69%, 70%);
top: 20px;
margin-top: 60px;
padding: 5px;
}
#order-link {
color: white;
text-decoration: none;
}
.order-button {
width: 180px;
margin-left: auto;
margin-right: auto;
text-align: center;
}
.footer-container {
display: flex;
justify-content: flex-end;
align-items: center;
background: #9A9A9A;
height: 90px;
max-height: 90px;
}
.footer-logo {
height: 80px;
position: relative;
right: 10px;
}
.subscribe {
border-radius: 25px;
background: hsl(344, 69%, 70%);
padding: 5px 20px 5px 20px;
width: 80px;
}
#subscribe-link {
position: relative;
color: white;
text-decoration: none;
right: 40px;
}
<div class="menu-container">
<div class="menu">
<div class="flex-item">About Us</div>
<div class="flex-item">Cakes</div>
<div class="flex-item">Cupcakes</div>
<div class="flex-item">Gallery</div>
<div class="flex-item">Prices/Order</div>
<div class="flex-item">Search</div>
</div>
</div>
<header class="header-container">
<img src="TCCLogo.png" class="logo" />
</header>
<div class="flex-container main">
<div class="container">
<div class="carousel">
Here is where I will have the quick gallery/carousel when I get to JS.
</div>
<div class="buttons">
<div class="button">
<img src="cake.png" />
<p>Check out our delicious cake options!</p>
</div>
<div class="button">
<img src="cupcake.png" />
<p>Check out our delicious cupcake options!</p>
</div>
<div class="button">
<img src="prices.png" />
<p>Check out our competitive pricing!</p>
</div>
</div>
</div>
</div>
<footer class="footer-container">
<a id="subscribe-link" target="_blank" href="#">
<div class="subscribe">
<p>Subscribe</p>
</div>
</a>
<img src="TCCLogo.png" class="footer-logo" />
</footer>
I have tried going through my stylesheet, changing the widths on anything I have set with pixels to percentages, but it didn't seem to fix it. The only thing that -sort of- worked was changing the body position to fixed, but then none of the content was view-able if it got shrunk down, all it fixed was keeping the background/header/footer colors the same.
I imagine maybe my coding is a bit messy - I tried my best to be extensible, but being 100% new at this made it difficult.
Your problem is that you have width:1600px in .buttons just remove it and also add box-sizing:border-box to all (pseudo-)elements
EDIT:
you also need to add max-width:100% to .container and flex-wrap:wrap in .buttons
*,
*::before,
*::after {
margin: 0;
padding: 0;
box-sizing: border-box
}
body {
font-family: Segoe UI, helvetica, arial;
display: flex;
flex-direction: column;
min-height: 100vh;
font-size: 18px;
}
a {
color: hsl(344, 69%, 70%);
font-weight: bold;
}
a:hover {
text-decoration: none;
color: #67c3b2;
}
.menu-container {
background-color: rgba(150, 150, 150, 0.2);
padding: 20px 0;
display: flex;
justify-content: center;
text-transform: uppercase;
width: 100%;
}
.menu {
width: 90%;
display: flex;
top: 10px;
justify-content: space-between;
font-size: 16px;
overflow: hidden;
position: relative;
left: 10px;
}
.header-container {
background-color: rgba(150, 150, 150, 0.2);
display: flex;
justify-content: center;
height: 30px;
width: 100%;
position: relative;
}
.logo {
position: relative;
bottom: 37px;
z-index: 1;
}
.flex-container {
display: flex;
justify-content: center;
}
.flex-container p {
position: relative;
margin-left: 40px;
margin-right: 40px;
font-weight: bold;
top: 40px;
margin-top: 40px;
text-align: center;
}
.main {
display: flex;
color: #464646;
background: linear-gradient(to right, #77C9D4, #57BC90);
flex: 1;
}
.cakelist {
position: relative;
bottom: 50px;
display: flex;
font-weight: bold;
list-style-position: inside;
margin-top: 130px;
}
.cakelist ol,
table {
margin-left: 25px;
}
.cakelist h2 {
margin-left: 25px;
margin-top: 20px;
}
.container {
max-width: 100%
}
.carousel {
color: #464646;
top: 80px;
position: relative;
display: flex;
justify-content: center;
border: 3px outset gray;
align-items: center;
padding: 60px;
}
.buttons {
position: relative;
margin-right: 25px;
justify-content: space-around;
display: flex;
flex-wrap: wrap;
top: 160px;
text-align: center;
}
.button a:hover {
opacity: 0.2;
}
.buttons p {
margin-top: 20px;
}
.buttons img {
padding-top: 25px;
height: 200px;
}
.gallery {
position: relative;
top: 80px;
}
.pricing {
display: flex;
position: relative;
top: 80px;
justify-content: center;
flex-direction: column;
padding-bottom: 140px;
}
.pricing p,
h1 {
margin-left: 250px;
text-align: left;
margin-top: 5px;
}
.pricing span {
opacity: 0;
user-select: none;
}
.order {
position: relative;
border-radius: 5px;
background: hsl(344, 69%, 70%);
top: 20px;
margin-top: 60px;
padding: 5px;
}
#order-link {
color: white;
text-decoration: none;
}
.order-button {
width: 180px;
margin-left: auto;
margin-right: auto;
text-align: center;
}
.footer-container {
display: flex;
justify-content: flex-end;
align-items: center;
background: #9A9A9A;
height: 90px;
max-height: 90px;
}
.footer-logo {
height: 80px;
position: relative;
right: 10px;
}
.subscribe {
border-radius: 25px;
background: hsl(344, 69%, 70%);
padding: 5px 20px 5px 20px;
width: 80px;
}
#subscribe-link {
position: relative;
color: white;
text-decoration: none;
right: 40px;
}
<div class="menu-container">
<div class="menu">
<div class="flex-item">About Us</div>
<div class="flex-item">Cakes</div>
<div class="flex-item">Cupcakes</div>
<div class="flex-item">Gallery</div>
<div class="flex-item">Prices/Order</div>
<div class="flex-item">Search</div>
</div>
</div>
<header class="header-container">
<img src="TCCLogo.png" class="logo" />
</header>
<div class="flex-container main">
<div class="container">
<div class="carousel">
Here is where I will have the quick gallery/carousel when I get to JS.
</div>
<div class="buttons">
<div class="button">
<img src="cake.png" />
<p>Check out our delicious cake options!</p>
</div>
<div class="button">
<img src="cupcake.png" />
<p>Check out our delicious cupcake options!</p>
</div>
<div class="button">
<img src="prices.png" />
<p>Check out our competitive pricing!</p>
</div>
</div>
</div>
</div>
<footer class="footer-container">
<a id="subscribe-link" target="_blank" href="#">
<div class="subscribe">
<p>Subscribe</p>
</div>
</a>
<img src="TCCLogo.png" class="footer-logo" />
</footer>
I have made it proper as you needed. And it's working for me.
Please add below css
.container, .buttons {
max-width: 100%;
}

Element width displayed incorrectly

The problem is that my header has a fixed width of 150px, but in browser it gets displayed as 134.984px and I can't figure out why. I've tried everthing that I could think of but nothing worked. The only thing I've managed to figure out is that it's the content-wrap flex item that is pushing on the headerand making it smaller.
Here's the HTML:
/*======= Container =======*/
#container{
display: flex;
flex-direction: row;
min-height: 100vh;
}
#content-wrap {
width: 100%;
}
/*======= Sāna izvēlne / header =======*/
header {
min-height: 100vh;
width: 150px;
margin: 0;
}
.header-position {
width: inherit;
height: 100vh;
position: fixed;
display: flex;
flex-direction: column;
justify-content: space-between;
}
nav {
background-color: #ffffff;
}
nav ul{
padding: 0;
margin: 0;
}
nav li, a {
text-decoration: none;
list-style-type: none;
text-align: right;
font-size: 1em;
color: black;
}
.logo {
background: url("../images/AG.svg");
background-size: contain;
background-repeat: no-repeat;
width: 80px;
}
/*======= Banneris =======*/
.banner-container {
background-image: url("../images/lp-background.jpg");
background-size: cover;
background-repeat: no-repeat;
width: 100%;
height: 300px;
clear: right;
}
.banner {
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
height: 100%;
}
.banner h1 {
color: white;
font-family: 'Roboto', sans-serif;
text-transform: uppercase;
font-weight: bold;
letter-spacing: 0.4em;
border: solid 10px white;
padding: 20px 30px;
}
/*======= Par mums =======*/
#about {
width: 100%;
height: 300px;
background-color: pink;
}
#about .first, .second {
width: 50%;
height: 100%;
display: inline-block;
}
#about .first {
}
#about .second {
float: right;
}
.about-picture {
height: 200px;
width: 200px;
margin: 50px 50px;
border-radius: 150px;
border: solid 4px rgb(246, 243, 199);
}
.about-picture.right {
float: right;
}
img.right {
float: right;
}
<div id="container">
<header>
<div class="header-position">
<img class="logo" src="./images/AG.svg" alt="AG Logo"></img>
<nav>
<ul>
<li>Sākums</li>
<li>Attēli</li>
<li>Kontakti</li>
<li>Par mums</li>
</ul>
</nav>
Sazinies ar mums
</div>
</header>
<div id="content-wrap">
<div class="banner-container">
<span class="banner"><h1>Whatever</h1></span>
</div>
<div id="about">
<div class="first">
<img class="about-picture left" src="./images/lp-background.jpg" alt="" />
</div>
<div class="second">
<img class="about-picture right" src="./images/lp-background.jpg" alt="" />
</div>
</div>
</div>
How do I get the 'header' to be displayed correctly?
As it's a flex-item you need to set it's flex properties accordingly.
header {
min-height: 100vh;
width: 150px;
margin: 0;
background-color: red;
flex: 0 0 150px; /* don't grow, don't shrink, be 150px wide */
}
/*======= Container =======*/
#container {
display: flex;
flex-direction: row;
min-height: 100vh;
}
#content-wrap {
width: 100%;
}
/*======= Sāna izvēlne / header =======*/
header {
min-height: 100vh;
width: 150px;
margin: 0;
background-color: red;
flex: 0 0 150px;
}
.header-position {
width: inherit;
height: 100vh;
position: fixed;
display: flex;
flex-direction: column;
justify-content: space-between;
}
nav {
background-color: #ffffff;
}
nav ul {
padding: 0;
margin: 0;
}
nav li,
a {
text-decoration: none;
list-style-type: none;
text-align: right;
font-size: 1em;
color: black;
}
.logo {
background: url("../images/AG.svg");
background-size: contain;
background-repeat: no-repeat;
width: 80px;
}
/*======= Banneris =======*/
.banner-container {
background-image: url("../images/lp-background.jpg");
background-size: cover;
background-repeat: no-repeat;
width: 100%;
height: 300px;
clear: right;
}
.banner {
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
height: 100%;
}
.banner h1 {
color: white;
font-family: 'Roboto', sans-serif;
text-transform: uppercase;
font-weight: bold;
letter-spacing: 0.4em;
border: solid 10px white;
padding: 20px 30px;
}
/*======= Par mums =======*/
#about {
width: 100%;
height: 300px;
background-color: pink;
}
#about .first,
.second {
width: 50%;
height: 100%;
display: inline-block;
}
#about .first {} #about .second {
float: right;
}
.about-picture {
height: 200px;
width: 200px;
margin: 50px 50px;
border-radius: 150px;
border: solid 4px rgb(246, 243, 199);
}
.about-picture.right {
float: right;
}
img.right {
float: right;
}
<div id="container">
<header>
<div class="header-position">
<img class="logo" src="./images/AG.svg" alt="AG Logo"></img>
<nav>
<ul>
<li>Sākums
</li>
<li>Attēli
</li>
<li>Kontakti
</li>
<li>Par mums
</li>
</ul>
</nav>
Sazinies ar mums
</div>
</header>
<div id="content-wrap">
<div class="banner-container">
<span class="banner"><h1>Whatever</h1></span>
</div>
<div id="about">
<div class="first">
<img class="about-picture left" src="./images/lp-background.jpg" alt="" />
</div>
<div class="second">
<img class="about-picture right" src="./images/lp-background.jpg" alt="" />
</div>
</div>
</div>