Expand transparent background on hover effect of an icon - html

I need some help to simply/correct my code.
I have an icon and I want its transparent background to go over the entire image it is hovering on. I think my approach is wrong with what I am doing now. Some suggestions?
My understanding of hover is still at the beginning and I am trying to build stuff in order to fully grasp it.
Here is the code:
body {
background-color: hsl(217, 54%, 11%);
}
.container {
width: 19rem;
height: 32rem;
margin: auto;
font-family: "Outfit", sans-serif;
background-color: hsl(216, 50%, 16%);
padding: 1rem;
margin-top: 8.5rem;
border-radius: 0.7rem;
box-shadow: 1px 1px 5px black;
}
/* I need help here*/
.equilibrium {
width: 19rem;
border-radius: 0.7rem;
cursor: pointer;
}
.image-hover:hover .view {
display: block;
background-color: hsl(178, 100%, 50%, 0.5);
}
.view {
position: absolute;
display: none;
top: 42%;
right: 47.5%;
}
.equilibrium .container h4:hover {
color: cyan;
}
.container h4 {
color: white;
}
.container p {
color: hsl(215, 51%, 70%);
font-size: 0.9rem;
}
.details {
display: flex;
justify-content: space-between;
padding-bottom: 1rem;
}
.ethereum {
color: cyan;
font-size: 0.8rem;
}
.clock {
color: hsl(215, 51%, 70%);
font-size: 0.8rem;
}
.ethereum img,
.clock img {
padding-right: 0.3rem;
position: relative;
top: 0.2rem;
}
.creator {
color: white;
}
.creator img {
height: 1.7rem;
border: 1px solid white;
border-radius: 50%;
}
.text {
position: relative;
left: 0.7rem;
bottom: 0.7rem;
}
.sub-text {
color: white;
}
.sub-text:hover {
color: cyan;
}
hr {
border: 1px solid rgb(88, 88, 88);
}
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<link
rel="icon"
type="image/png"
sizes="32x32"
href="./images/favicon-32x32.png"
/>
<link rel="stylesheet" href="style.css" />
<link
rel="stylesheet"
href="https://fonts.googleapis.com/css?family=Outfit"
/>
<title>Frontend Mentor | NFT preview card component</title>
</head>
<body>
<div class="container">
<div class="image-hover">
<img src="./images/image-equilibrium.jpg" class="equilibrium" alt="" />
<img src="./images/icon-view.svg" alt="view image" class="view" />
</div>
<h4>Equilibrium #3429</h4>
<p>
Our Equilibrium collection promotes <br />
balance and calm.
</p>
<div class="details">
<span class="ethereum"
><img src="./images/icon-ethereum.svg" alt="" />0.041 ETH</span
>
<span class="clock"
><img src="./images/icon-clock.svg" alt="" />3 days left</span
>
</div>
<hr />
<p class="creator">
<img src="./images/image-avatar.png" alt="" /><span class="text"
>Creation of<span class="sub-text"> Jules Wyvern</span></span
>
</p>
</div>
</body>
</html>

Related

vertical Scrollbar appearing in my practice project

I am trying to improve my css skills by practicing making and cloning various projects , I was practicing this nft project from frontendmentor and faced this problem , A vertical scrollbar always appear on my web page and I don't know why is this happening , I have tried changing the height of my main container from 50% to 33% but the problem remains the same , I am attaching the code for your reference
#import url(https://fonts.google.com/specimen/Outfit);
:root {
--Soft-blue: hsl(215, 51%, 70%);
--Cyan: hsl(178, 100%, 50%);
--Very-dark-blue1: hsl(217, 54%, 11%);
--Very-dark-blue2: hsl(216, 50%, 16%);
--Very-dark-blue3: hsl(215, 32%, 27%);
--White: hsl(0, 0%, 100%)
}
* {
margin: 0;
padding: 0;
box-sizing: border-box;
}
body {
background-color: var(--Very-dark-blue1);
color: var(--White);
font-family: "Outfit", sans-serif;
font-size: 18px;
}
.container {
width: 33%;
height: 50%;
margin: 3em auto;
overflow: hidden;
background-color: var(--Very-dark-blue2);
border-radius: 12px;
display: flex;
flex-direction: column;
text-align: left;
}
.nft {
width: 100%;
height: 40%;
border-radius: 12px;
}
.nft img {
width: 100%;
height: 100%;
padding: 2em;
border-radius: 12%;
}
h3.title-nft {
color: var(--White);
padding: 0 1.5em;
}
p.info {
color: var(--Soft-blue);
font-weight: 300;
padding: 1.75em;
letter-spacing: 0.1em;
}
ul {
display: flex;
justify-content: space-between;
list-style: none;
}
li {
padding: 1.75em;
}
li.eth {
color: var(--Cyan);
}
li.clock {
color: var(--Soft-blue);
}
hr {
width: 80%;
margin: 0 auto;
border-color: var(--Very-dark-blue3);
}
.footer {
display: flex;
align-items: center;
justify-content: flex-start;
margin: 2em;
}
.footer img {
border-radius: 50%;
width: 3em;
border: 2px solid var(--White);
margin-right: 1.75em;
}
.footer p {
color: var(--Soft-blue);
}
.footer span {
color: var(--White);
}
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<link rel="icon" type="image/png" sizes="32x32" href="./images/favicon-32x32.png" />
<link rel="stylesheet" href="styles.css" />
<link rel="stylesheet" href="path/to/font-awesome/css/font-awesome.min.css" />
<title>Frontend Mentor | NFT preview card component</title>
</head>
<body>
<div class="container">
<div class="nft">
<img src="images/image-equilibrium.jpg" />
</div>
<div class="main-content">
<h3 class="title-nft">Equilbirium #3429</h3>
<p class="info">Our Equilibirum collection promotes balance and calm</p>
<div class="side-details">
<ul>
<li class="eth">
<img src="images/icon-ethereum.svg" /> 0.041 ETH
</li>
<li class="clock">
<img src="images/icon-clock.svg" /> 3 Days Left
</li>
</ul>
</div>
</div>
<hr />
<div class="footer">
<img src="images/image-avatar.png" />
<p class="creator">
Creation of <span class="wrapper">Jules Wyvern </span>
</p>
</div>
</div>
</body>
</html>
I can't answer why, but container ignore height: 33%, and using 100% + border. This and create problem. You can try use 33vh.

Debugging Flexbox - What am I missing?

I've been working on this project and I am fully stuck on ensuringing both cards (the image and the project content) are on the same row when displayed on desktop. After a few days, I admit I need help.
Can anyone tell me where I've gone wrong and how I can solve this using flexbox correctly because I am going crosseyed trying to figure it out.
Below is a photo of what it's supposed to look like in desktop.
* {
box-sizing: border-box;
margin: 0;
padding: 0;
}
body {
align-items: center;
background-color: hsl(30, 38%, 92%);
color: hsl(228, 12%, 48%);
display: flex;
font-family: 'Montserrat', sans-serif;
font-size: 0.875em;
justify-content: center;
height: 100vh;
}
h1 {
color: black;
font-family: 'Fraunces', serif;
font-size: 1.875em;
}
h3 {
font-size: 0.75em;
font-weight: 500;
letter-spacing: 7px;
text-transform: uppercase;
}
p {
font-size: 0.75em;
line-height: 1.7;
}
/* ------ ENTIRE CONTAINER --------- */
#card-container {
align-items: center;
justify-content: center;
/* flex-wrap: wrap; */
flex-direction: row;
width: 700px;
margin: 0 auto;
}
#card-container row {
display: flex;
flex-direction: row;
margin: 0;
}
#media screen and (max-width : 667px) {
#container {
border-radius: 10px 0 10px 0;
height: 39.7em;
width: 22.8em;
}
}
/* ------ LEFT CONTAINER w/ IMAGE --------- */
.image {
background-image: url(images/image-product-desktop.jpg);
background-repeat: no-repeat;
background-size: contain;
border-radius: 10px 0 0 10px;
height: 394px;
max-width: 50%;
margin-right: 0;
display: flex;
flex-direction: row;
}
#media screen and (max-width : 667px) {
.image {
background-image: url(images/image-product-mobile.jpg);
border-radius: 10px 10px 0 0;
height: 230px;
width: 50%;
margin: 0 auto;
}
}
/* ------RIGHT CONTAINER w/ CONTENT --------- */
.right-container {
background-color: white;
border-radius: 0 10px 10px 0;
height: 450px;
padding: 2em;
width: 50%;
}
#media screen and (max-width : 667px) {
.right-container {
border-bottom-left-radius: 10px;
border-top-right-radius: 0px;
padding: 30px 30px 5px;
width: 50%;
margin: 0 auto;
}
}
.right-container h1 {
margin: auto auto 7% auto;
}
.right-container h3 {
padding-bottom: 1em;
padding-top: 1.9em;
}
.right-container p {
padding-right: 2em;
padding-top: 1.1em;
}
/* ------ PRICES --------- */
.price-container h1 {
color: hsl(158, 36%, 37%);
display: inline-block;
margin-top: 20%;
}
.price-container p {
display: inline-block;
margin-left: 5em;
text-decoration: line-through;
}
/* ------- ADD TO CART --------- */
.cart-btn {
background-color: hsl(158, 36%, 37%);
background-position: 4em;
background-repeat: no-repeat;
border-radius: 10px;
border: transparent;
color: white;
font-family: 'Montserrat', sans-serif;
font-size: 15px;
padding: 4% 32%;
}
.cart-btn:hover {
background-color: black;
cursor: pointer;
}
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0"> <!-- displays site properly based on user's device -->
<link rel="icon" type="image/png" sizes="32x32" href="./images/favicon-32x32.png">
<title>Product preview card component</title>
<!-- CSS STYLESHEET-->
<link rel="stylesheet" href="styles.css">
<!-- GOOGLE FONTS -->
<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=Fraunces:opsz,wght#9..144,700&family=Montserrat:wght#500;700&display=swap"
rel="stylesheet">
</head>
<body>
<section class="card-container">
<div class="row">
<div class="image">
<div class="img-desktop"></div>
<div class="img-mobile"></div>
</div>
</div>
<div class="row">
<div class="right-container">
<h3>Perfume</h3>
<h1>Gabrielle Essence Eau De Parfum</h1>
<p>A floral, solar and voluptuous interpretation composed by Olivier Polge,
Perfumer-Creator for the House of CHANEL.</p>
<div class="price-container">
<h1>$149.99</h1>
<p>$169.99</p>
</div>
<div class="cart-container">
<img src="./images/icon-cart.svg" alt="card-img">
<button class="cart-btn">Add to Cart</button>
</div>
</div>
</div>
</section>
</body>
</html>
To solve this I simply put the element with the background-image in a new div called .left-container. I removed the use of two .row's and put them in one row and set it to display: flex;. I then used Font Awesome for your shopping cart icon.
* {
box-sizing: border-box;
margin: 0;
padding: 0;
}
body {
align-items: center;
background-color: hsl(30, 38%, 92%);
color: hsl(228, 12%, 48%);
display: flex;
font-family: 'Montserrat', sans-serif;
font-size: 0.875em;
justify-content: center;
height: 100vh;
}
h1 {
color: black;
font-family: 'Fraunces', serif;
font-size: 1.875em;
}
h3 {
font-size: 0.75em;
font-weight: 500;
letter-spacing: 7px;
text-transform: uppercase;
}
p {
font-size: 0.75em;
line-height: 1.7;
}
.row {
display: flex;
}
/* ------ ENTIRE CONTAINER --------- */
#card-container {
align-items: center;
justify-content: center;
/* flex-wrap: wrap; */
flex-direction: row;
width: 700px;
margin: 0 auto;
}
#card-container row {
display: flex;
flex-direction: row;
margin: 0;
}
/* ------ LEFT CONTAINER w/ IMAGE --------- */
.left-container {
width: 50%;
height: 450px;
}
.image {
background-image: url(https://i.picsum.photos/id/487/200/300.jpg?grayscale&hmac=j_GpFy8cDZyFmRD6sSG09M39jrZwpW3dCYWYnWlC1Vo);
background-repeat: no-repeat;
background-size: cover;
background-position: center;
height: 100%;
width: 100%;
border-radius: 10px 0 0 10px;
margin-right: 0;
display: flex;
flex-direction: row;
}
/* ------RIGHT CONTAINER w/ CONTENT --------- */
.right-container {
background-color: white;
border-radius: 0 10px 10px 0;
height: 450px;
padding: 2em;
width: 50%;
display: flex;
flex-flow: column;
justify-content: space-around;
}
.right-container h3 {
padding-bottom: 1em;
padding-top: 1.9em;
}
.right-container p {
padding-right: 2em;
padding-top: 1.1em;
}
/* ------ PRICES --------- */
.price-container h1 {
color: hsl(158, 36%, 37%);
display: inline-block;
margin-top: 20%;
}
.price-container p {
display: inline-block;
margin-left: 5em;
text-decoration: line-through;
}
/* ------- ADD TO CART --------- */
.cart-btn {
background-color: hsl(158, 36%, 37%);
background-position: 4em;
background-repeat: no-repeat;
border-radius: 10px;
border: transparent;
color: white;
font-family: 'Montserrat', sans-serif;
font-size: 15px;
width: 100%;
padding: 1em;
}
.cart-btn:hover {
background-color: black;
cursor: pointer;
}
i {
color: white;
}
.card-container {
display: flex;
}
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<!-- displays site properly based on user's device -->
<link rel="icon" type="image/png" sizes="32x32" href="./images/favicon-32x32.png">
<title>Product preview card component</title>
<!-- CSS STYLESHEET-->
<link rel="stylesheet" href="styles.css">
<!-- GOOGLE FONTS -->
<link rel="preconnect" href="https://fonts.googleapis.com">
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
<script src="https://kit.fontawesome.com/6140596fcb.js" crossorigin="anonymous"></script>
<link href="https://fonts.googleapis.com/css2?family=Fraunces:opsz,wght#9..144,700&family=Montserrat:wght#500;700&display=swap" rel="stylesheet">
</head>
<body>
<section class="card-container">
<div class="row">
<div class="left-container">
<div class="image">
<div class="img-desktop"></div>
<div class="img-mobile"></div>
</div>
</div>
<div class="right-container">
<h3>Perfume</h3>
<h1>Gabrielle Essence Eau De Parfum</h1>
<p>A floral, solar and voluptuous interpretation composed by Olivier Polge, Perfumer-Creator for the House of CHANEL.</p>
<div class="price-container">
<h1>$149.99</h1>
<p>$169.99</p>
</div>
<div class="cart-container">
<button class="cart-btn"><i class="fa-solid fa-cart-shopping"></i>
Add to Cart</button>
</div>
</div>
</div>
</section>
</body>
</html>
I have made my self page that replicates the solution you want, I have done minimal styling to make you understand how flexbox properties in CSS work (NOTE: I have not made it responsive so try to have a look on desktop view). Refer to my solution and ask question(s) if you are facing any doubts.
* {
margin: 0;
padding: 0;
}
.card-container {
display: flex;
justify-content: center;
align-items: center;
width: 100%;
height: 100vh;
background-color: hsl(30, 38%, 92%);
color: hsl(228, 12%, 48%);
font-family: "Montserrat", sans-serif;
font-size: 0.875em;
}
#random-image {
height: 100%;
width: 100%;
border-top-left-radius: 8px;
border-bottom-left-radius: 8px;
}
.intermediate-container {
display: flex;
width: 60%;
height: 50%;
border-radius: 8px;
box-shadow: 2px 2px 8px rgba(0, 0, 0, 0.55);
}
.left-container {
width: 50%;
}
.right-container {
width: 50%;
padding: 10px;
background-color: white;
border-top-right-radius: 8px;
border-bottom-right-radius: 8px;
display: flex;
justify-content: center;
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" />
<link rel="stylesheet" href="styles.css" />
<title>Your title</title>
</head>
<body>
<section class="card-container">
<div class="intermediate-container">
<div class="left-container">
<img
id="random-image"
src="https://hatrabbits.com/wp-content/uploads/2017/01/random.jpg"
/>
</div>
<div class="right-container">
<div>
<h3>Perfume</h3>
<h1>Gabrielle Essence Eau De Parfum</h1>
<p>
A floral, solar and voluptuous interpretation composed by Olivier
Polge, Perfumer-Creator for the House of CHANEL.
</p>
<div class="price-container">
<h1>$149.99</h1>
</div>
<div class="cart-container">
<button class="cart-btn">
<i class="fa-solid fa-cart-shopping"></i> Add to Cart
</button>
</div>
</div>
</div>
</div>
</section>
</body>
</html>
#card-container row <- use proper selector (.row)
and from given information I can only predict that

Display an image on top of another CSS using hover

I'm trying to add some hover effects to my landing page and i'm stuck at doing the hover effect at the image, the hover in the title and author I was able to do easily.
I tried some stuff but I still couldn't do, the solutions that I saw here on stackoverflow was using position: absolute, but I was looking for some other solution (if there is).
If the main solution is using position: absolute and you want to please help me understand, I find very difficult to understand and use position: absolute.
Here's how my page look like right now
:root {
--soft-blue: hsl(215, 51%, 70%);
--cyan: hsl(178, 100%, 50%);
--main-bg: hsl(217, 54%, 11%);
--card-bg: hsl(216, 50%, 16%);
--line: hsl(215, 32%, 27%);
--white: hsl(0, 0%, 100%);
--font-size: 18px;
--font: 'Outfit', sans-serif;
}
body {
margin: 0;
font-family: var(--font);
}
.page {
display: flex;
height: 100vh;
background-color: var(--main-bg);
justify-content: center;
align-items: center;
}
.page__container {
box-sizing: border-box;
padding: 20px 20px 0px 20px;
background-color: var(--card-bg);
width: 400px;
height: 650px;
border-radius: 20px;
}
.page__container img {
margin: 0;
max-width: 100%;
max-height: 100%;
border-radius: 10px;
}
.page__container h1 {
color: var(--white);
font-size: 26px;
margin: 15px 0 10px;
}
.page__container h1 a {
color: var(--white);
text-decoration: none;
}
.page__container .description {
margin: 0;
font-weight: 400;
color: var(--soft-blue);
font-size: 20px;
}
.price-deadline {
display: flex;
align-items: center;
justify-content: space-between;
}
.eth {
display: flex;
align-items: center;
}
.eth .eth-icon {
max-height: 18px;
max-width: 11px;
margin-right: 5px;
}
.eth .eth-price {
color: var(--cyan);
}
.deadline {
display: flex;
align-items: center;
}
.deadline .clock-icon {
max-width: 17px;
max-height: 17px;
margin-right: 5px;
}
.deadline .due-date {
font-weight: 600;
color: var(--soft-blue);
}
.divisor {
height: 1px;
background-color: var(--soft-blue);
border: none;
}
.author {
display: flex;
align-items: center;
padding-top: 10px;
}
.author .avatar {
border: 1px solid white;
border-radius: 50px;
max-height: 40px;
max-width: 40px;
margin-right: 10px;
}
.author .credits {
color: var(--soft-blue);
}
.author a {
font-size: 16px;
color: var(--white);
text-decoration: none;
}
/* Hover Section */
.author a:hover {
color: var(--cyan);
}
.text h1 .link:hover {
color: var(--cyan);
}
<!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">
<link rel="stylesheet" href="style.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=Outfit:wght#300;400;600&display=swap" rel="stylesheet">
<link rel="shortcut icon" href="./images/favicon-32x32.png" type="image/x-icon">
<title>NFT Preview Card</title>
</head>
<body>
<div class="page">
<div class="page__container">
<img src="./images/image-equilibrium.jpg" alt="" class="equilibrium">
</p>
<div class="text">
<h1>Equilibrium #3429</h1>
<p class="description">
Our Equilibrium collection promotes
balance and calm.
</p>
<div class="price-deadline">
<div class="eth">
<img src="./images/icon-ethereum.svg" alt="" class="eth-icon">
<p class="eth-price">0.041 ETH</p>
</div>
<div class="deadline">
<img src="./images/icon-clock.svg" alt="" class="clock-icon">
<p class="due-date">3 days left</p>
</div>
</div>
</div>
<hr class="divisor">
<div class="author">
<img src="./images/image-avatar.png" alt="" class="avatar">
<p class="credits">
Creation of Jules Wyvern
</p>
</div>
</div>
</div>
</body>
</html>
i cannot think of another way without position: absolute
but i have created you an example where the the image is positioned automatically on the center using flex box https://jsfiddle.net/r5Lfcbh8/2/
Edit i use position relative on the parent div as relative make the children absolute top left 0 same as relative.
<div class="overlayPar">
<img src="https://media.marketrealist.com/brand-img/LyxvUFSpl/0x0/nft-black-1617613285599.jpg" alt="" class="equilibrium">
<div class="imgOverlay">
<span class="eye"></span>
</div>
</div>
.overlayPar {
position: relative;
}
.imgOverlay {
position: absolute;
top: 0;
left: 0;
right: 0;
bottom: 0;
background-color: rgba(0, 255, 247, .4);
display: none;
}
.imgOverlay .eye {
background: white;
width: 25px;
height: 25px;
display: block;
margin: auto;
}
.overlayPar:hover .imgOverlay {
display: flex;
}
.equilibrium {
display: block;
}

only centre second container [duplicate]

This question already has answers here:
Center and bottom-align flex items
(3 answers)
Closed 2 years ago.
i have a header-container and a quote-container within the body. I like the h1 element to be on the top left of the page and the quote-container in the center of the page.
I applied display:flex to the body and both header-container and quote-container get centered.
How can I center the quote-container only? Is it possible to achieve this using flexbox?
Below are the html and css files:
#import url("https://fonts.googleapis.com/css?family=Montserrat&display=swap");
html {
box-sizing: border-box;
}
body {
margin: 0;
min-height: 100vh;
font-family: Montserrat, sans-serif;
font-weight: 700;
text-align: center;
display: flex;
align-items: center;
justify-content: center;
}
.header-container {
margin: 0;
width: auto;
max-width: 250px;
text-align: center;
margin-bottom: 10px;
font-size: 1.8rem;
margin-left: 100px;
background-color: lightblue;
}
.quote-container {
width: auto;
max-width: 900px;
padding: 20px 30px;
border: 0.5px solid lightgray;
border-radius: 10px;
}
.quote-text {
font-size: 2.5rem;
}
.quote-author {
margin-top:15px;
font-size: 2rem;
font-weight: 400;
font-style: italic;
}
.button-container {
margin-top: 15px;
display: flex;
justify-content: space-between;
}
button {
cursor: pointer;
font-size: 1.2rem;
width: auto;
height: 2.5rem;
border:none;
border-radius: 10px;
color: #fff;
background: black;
outline: none;
padding: 0.5rem 1.8rem;
box-shadow: 0 0.3rem rgba(121,121,121,0.65);
}
button:hover {
filter:brightness(110%);
}
button:active {
transform: translate(0,0.3rem);
box-shadow: 0 0.1rem rbga(255,255,255,0.65);
}
.twitter-button:hover {
color: #38a1f3;
}
.fa-twitter {
font-size:1.5rem;
}
/* Loader */
.loader {
border: 16px solid #f3f3f3; /* Light grey */
border-top: 16px solid #333;
border-radius: 50%;
width: 120px;
height: 120px;
animation: spin 2s linear infinite;
}
#keyframes spin {
0% { transform: rotate(0deg); }
100% { transform: rotate(360deg); }
}
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Quotes</title>
<link rel="icon" type="image/png" href="favicon.png">
<!-- Old Favicon - Grab Icon From Google (Might be unsupported in the future) -->
<!-- <link rel="icon" type="image/png" href="https://s2.googleusercontent.com/s2/favicons?domain=jacinto.design"> -->
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.10.2/css/all.min.css"/>
<link rel="stylesheet" href="style.css">
</head>
<body>
<div class="header-container">
<h1>Quotes</h1>
</div>
<div class="quote-container" id="quote-container">
<div class="quote-text" id="quote-text">
<i class="fa fa-quote-left"></i>
<span id="quote"></span>
</div>
<div class="quote-author" id="author">
<span id = "author"></span>
</div>
<div class="button-container">
<button class="twitter-button" id="twitter" title="Tweet This!" >
<i class="fab fa-twitter"></i>
</button>
<button id="new-quote">New Quote</button>
</div>
</div>
<!-- Loader -->
<div class="loader" id="loader"></div>
<!-- Script -->
<script src="script.js"></script>
</body>
</html>
final output as below
Is that how you want to display?
#import url("https://fonts.googleapis.com/css?family=Montserrat&display=swap");
html {
box-sizing: border-box;
}
body {
margin: 0;
min-height: 100vh;
font-family: Montserrat, sans-serif;
font-weight: 700;
display: flex;
flex-direction: column;
}
.header-container {
margin: 0;
width: auto;
max-width: 250px;
text-align: center;
margin-bottom: 10px;
font-size: 1.8rem;
background-color: lightblue;
}
.quote-container {
width: auto;
max-width: 900px;
padding: 20px 30px;
border: 0.5px solid lightgray;
border-radius: 10px;
align-self: center;
justify-self: center;
}
.quote-text {
font-size: 2.5rem;
}
.quote-author {
margin-top:15px;
font-size: 2rem;
font-weight: 400;
font-style: italic;
}
.button-container {
margin-top: 15px;
display: flex;
justify-content: space-between;
}
button {
cursor: pointer;
font-size: 1.2rem;
width: auto;
height: 2.5rem;
border:none;
border-radius: 10px;
color: #fff;
background: black;
outline: none;
padding: 0.5rem 1.8rem;
box-shadow: 0 0.3rem rgba(121,121,121,0.65);
}
button:hover {
filter:brightness(110%);
}
button:active {
transform: translate(0,0.3rem);
box-shadow: 0 0.1rem rbga(255,255,255,0.65);
}
.twitter-button:hover {
color: #38a1f3;
}
.fa-twitter {
font-size:1.5rem;
}
/* Loader */
.loader {
border: 16px solid #f3f3f3; /* Light grey */
border-top: 16px solid #333;
border-radius: 50%;
width: 120px;
height: 120px;
animation: spin 2s linear infinite;
}
#keyframes spin {
0% { transform: rotate(0deg); }
100% { transform: rotate(360deg); }
}
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Quotes</title>
<link rel="icon" type="image/png" href="favicon.png">
<!-- Old Favicon - Grab Icon From Google (Might be unsupported in the future) -->
<!-- <link rel="icon" type="image/png" href="https://s2.googleusercontent.com/s2/favicons?domain=jacinto.design"> -->
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.10.2/css/all.min.css"/>
<link rel="stylesheet" href="style.css">
</head>
<body>
<div class="header-container">
<h1>Quotes</h1>
</div>
<div class="quote-container" id="quote-container">
<div class="quote-text" id="quote-text">
<i class="fa fa-quote-left"></i>
<span id="quote"></span>
</div>
<div class="quote-author" id="author">
<span id = "author"></span>
</div>
<div class="button-container">
<button class="twitter-button" id="twitter" title="Tweet This!" >
<i class="fab fa-twitter"></i>
</button>
<button id="new-quote">New Quote</button>
</div>
</div>
<!-- Loader -->
<div class="loader" id="loader"></div>
<!-- Script -->
<script src="script.js"></script>
</body>
</html>

HTML meta viewport is cutting my layout. Why is it happening?

I am building a responsive web page. Now I am going to start working with media queries, but when I insert <meta name="viewport" content="width=device-width"> and make the screen get smaller, part of the background of my header, first section and footer is cutted, remaining only a part of them and white space with their text. You can see it in the on the snippet. Why is it happening and what can I do do fix it?
#charset "UTF-8";
#import url('https://fonts.googleapis.com/css?family=Doppio+One|Open+Sans&display=swap');
body{
font-family: 'Open Sans', sans-serif;
margin: 0;
}
a{
text-decoration: none;
transition: 0.2s linear;
}
header{
background-color: rgb(93, 158, 76);
display: flex;
align-items: center;
padding: 0px 30px;
}
header img{
width: 45px;
}
header h1{
font-family: 'Doppio One', cursive;
margin-left: 10px;
color: rgb(214, 245, 210);
}
nav ul{
display: flex;
list-style: none;
}
nav ul li a{
margin-left: 55px;
}
nav a{
color: rgb(230, 245, 229);
font-size: 17px;
}
nav a:hover{
background-color: rgb(143, 182, 135);
padding: 10px 15px;
margin: 0 -15px 0 40px;
}
#firstsection{
background-image: url(Images/coffee-3289259_1280.jpg);
background-size: cover;
height: 900px;
position: relative;
}
#firstsection div{
margin-top: 0;
position: absolute;
left: 100px;
top: 150px;
color: rgb(47, 119, 27);
text-align: center;
}
#firstsection h1{
margin-bottom: 45px;
}
#firstsection div a{
font-weight: bold;
border: 2px solid rgb(47, 119, 27);
padding: 13px 30px;
font-size: 16.5px;
color: rgb(47, 119, 27);
}
#firstsection div a:hover{
color: rgb(133, 163, 131);
border: 2px solid rgb(133, 163, 131);
}
#textboxes{
display: flex;
margin-top: 50px;
}
#middlesection div div{
text-align: center;
margin: 15px 60px;
border: 2px solid rgb(93, 158, 76);
padding: 30px 30px;
}
#middlesection img:first-of-type{
width: 55px;
}
#middlesection h2{
text-align: center;
width: 100%;
}
#lastsection{
text-align: center;
}
#lastsection img{
width: 500px;
margin: 100px auto 0px;
}
#lastsection div{
position: relative;
bottom: 450px;
}
#lastsection div a:visited{
color: blue;
}
footer{
background-color: rgb(93, 158, 76);
padding: 15px;
color: rgb(214, 245, 210);
font-size: 14px;
display: flex;
justify-content: center;
align-items: center;
}
footer img{
height: 35px;
width: 35px;
margin-right: 15px;
}
footer div{
text-align: center;
}
<!DOCTYPE html>
<html>
<head>
<title>Finances | Manage your money easily</title>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width">
<meta name="description" content="Control you spending and manage your money easily. Your finances by the short hairs.">
<meta name="author" content="Bruno M. B. Sdoukos">
<meta name="keywords" content="finances, managing money, spending control">
<link rel="stylesheet" type="text/css" href="stylesheet.css">
<link rel="stylesheet" type="text/css" href="https://necolas.github.io/normalize.css/8.0.1/normalize.css">
</head>
<body>
<header>
<img src="Images/icons8-fund-accounting-80.png">
<h1>Finances</h1>
<nav>
<ul>
<li>Home</li>
<li>About</li>
<li>Contact us</li>
<li>Register</li>
<li>Login</li>
</ul>
</nav>
</header>
<main>
<section id="firstsection">
<div>
<h1>Manage your money easily, anywhere, anytime.</h1>
Get started
</div>
</section>
<section id="middlesection">
<div id="textboxes">
<div>
<img src="Images/icons8-increase-64.png">
<h3>Concrete data</h3>
<p>Simple but concrete data that are the answer to all the quesions about your current money, spending and.</p>
</div>
<div>
<img src="Images/icons8-navigation-toolbar-left-filled-50 (1).png">
<h3>Easy interface</h3>
<p>An interface easy to use, made to you who want to manage your money faster and with no problems.</p>
</div>
<div>
<img src="Images/icons8-natural-user-interface-2-filled-50.png">
<h3>Fast access</h3>
<p>No complications that make you lose time. Just some clicks and done, you are in Finances, with all you need.</p>
</div>
</div>
</section>
<section id="lastsection">
<img src="Images/board-1362851_1280.png">
<div>
<h2>Register now and enjoy<br>the best of Finances.</h2>
Create an account
</div>
</section>
</main>
<footer>
<img src="Images/icons8-fund-accounting-80.png">
<div>
<p>A work of Bruno Sdoukos.</p>
</div>
</footer>
</body>
</html>
Have made some changes to your code. The initial problem was with the midsection. When the midsection has a width greater than the screen width a horizontal scrollbar appears to allow the user to see the rest of the content.
To fix that you could make the alignment vertical instead of horizontal depending on the width of the screen. In the solution below I wrap the content.
The second problem was when the width of the contents in the header exceeds the width of the screen that is when the width of the container tries to be the same width as the screen(remember the meta name="viewport") but the content overflows(as it has a greater width).
To fix that you could show your header items inside of a menu. In my solution below I have just made it take no space in the header(display: none). E.g solution might be like this.
NOTE: The solution below does not have elegant styling maybe you could add a padding here and there to make it look elegant
<!DOCTYPE html>
<html>
<head>
<title>Finances | Manage your money easily</title>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width" />
<meta
name="description"
content="Control you spending and manage your money easily. Your finances by the short hairs."
/>
<meta name="author" content="Bruno M. B. Sdoukos" />
<meta
name="keywords"
content="finances, managing money, spending control"
/>
<link rel="stylesheet" type="text/css" href="stylesheet.css" />
<link
rel="stylesheet"
type="text/css"
href="https://necolas.github.io/normalize.css/8.0.1/normalize.css"
/>
<link
rel="stylesheet"
href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css"
/>
</head>
<body>
<script>
function myFunction() {
var x = document.getElementById("topulid");
if (x.className === "topul") {
x.className += " responsive";
} else {
x.className = "topul";
}
}
</script>
<header>
<img src="Images/icons8-fund-accounting-80.png"/>
<h1>Finances</h1>
<div class="topnav" id="myTopnav">
Home
News
Contact
About
<a href="javascript:void(0);" class="icon" onclick="myFunction()">
<i class="fa fa-bars"></i>
</a>
</div>
</header>
<main>
<section id="firstsection">
<div>
<h1>Manage your money easily, anywhere, anytime.</h1>
Get started
</div>
</section>
<section id="middlesection">
<div id="textboxes">
<div>
<img src="Images/icons8-increase-64.png" />
<h3>Concrete data</h3>
<p>
Simple but concrete data that are the answer to all the quesions
about your current money, spending and.
</p>
</div>
<div>
<img
src="Images/icons8-navigation-toolbar-left-filled-50 (1).png"
/>
<h3>Easy interface</h3>
<p>
An interface easy to use, made to you who want to manage your
money faster and with no problems.
</p>
</div>
<div>
<img src="Images/icons8-natural-user-interface-2-filled-50.png" />
<h3>Fast access</h3>
<p>
No complications that make you lose time. Just some clicks and
done, you are in Finances, with all you need.
</p>
</div>
</div>
</section>
<section id="lastsection">
<img src="Images/board-1362851_1280.png" />
<div>
<h2>Register now and enjoy<br />the best of Finances.</h2>
Create an account
</div>
</section>
</main>
<footer>
<img src="Images/icons8-fund-accounting-80.png" />
<div>
<p>A work of Bruno Sdoukos.</p>
</div>
</footer>
</body>
</html>
#charset "UTF-8";
#import url("https://fonts.googleapis.com/css?family=Doppio+One|Open+Sans&display=swap");
body {
font-family: "Open Sans", sans-serif;
margin: 0;
}
a {
text-decoration: none;
transition: 0.2s linear;
}
header {
background-color: rgb(93, 158, 76);
display: flex;
align-items: center;
}
header img {
width: 45px;
}
header h1 {
font-family: "Doppio One", cursive;
margin-left: 10px;
color: rgb(214, 245, 210);
}
.topnav {
overflow: hidden;
flex: 1;
display: flex;
justify-content: space-around;
align-items: center;
max-width: 500px;
padding-left: 50px;
}
.topnav a {
color: #f2f2f2;
text-align: center;
padding: 14px 16px;
text-decoration: none;
font-size: 17px;
}
.topnav .icon {
display: none;
}
.icon {
display: none;
}
#firstsection {
background-image: url(Images/coffee-3289259_1280.jpg);
background-size: cover;
height: 900px;
position: relative;
}
#firstsection div {
margin-top: 0;
position: absolute;
left: 100px;
top: 150px;
color: rgb(47, 119, 27);
text-align: center;
}
#firstsection h1 {
margin-bottom: 45px;
}
#firstsection div a {
font-weight: bold;
border: 2px solid rgb(47, 119, 27);
padding: 13px 30px;
font-size: 16.5px;
color: rgb(47, 119, 27);
}
#firstsection div a:hover {
color: rgb(133, 163, 131);
border: 2px solid rgb(133, 163, 131);
}
#textboxes {
display: flex;
/* flex-wrap: wrap; */
margin-top: 50px;
justify-content: space-around;
flex-wrap: wrap;
}
#middlesection div div {
text-align: center;
/* margin: 15px 0px; */
border: 2px solid rgb(93, 158, 76);
padding: 30px 30px;
max-width: 300px;
}
#middlesection img:first-of-type {
width: 55px;
}
#middlesection h2 {
text-align: center;
width: 100%;
}
#lastsection {
text-align: center;
}
#lastsection img {
width: 500px;
margin: 100px auto 0px;
}
#lastsection div {
position: relative;
bottom: 450px;
}
#lastsection div a:visited {
color: blue;
}
footer {
background-color: rgb(93, 158, 76);
padding: 15px;
color: rgb(214, 245, 210);
font-size: 14px;
display: flex;
justify-content: center;
align-items: center;
}
footer img {
height: 35px;
width: 35px;
margin-right: 15px;
}
footer div {
text-align: center;
}
#media screen and (max-width: 830px) {
.topnav a {
display: none;
}
.icon {
float: right;
display: block;
}
}
Do a simple global reset with:
html,
body,
*,
*::before,
*::after {
margin: 0;
padding: 0;
box-sizing: border-box;
}
then set the body to:
body {
width: 100vw;
}