How to get rid of unwanted space in CSS grid? [duplicate] - html

This question already has an answer here:
CSS Grid vs dynamic definition list autoplacement
(1 answer)
Closed 6 months ago.
I am building a calculator with HTML, CSS, and JavaScript. I am facing difficulty building the basic design of the app.
I have no clue why the space is in there. I tried adding negative margin but that didn't work too.
GOAL
CURRENT STATE
.container {
height: 500px;
width: 400px;
background-color: #3333;
border-radius: 10px;
}
.output {
height: 100px;
padding: 3rem 3rem 6rem 3rem;
font-size: 2.5rem;
text-align: right;
background-color: #eee;
border-radius: 10px;
}
.buttons {
width: 400px;
display: grid;
row-gap: 1%;
padding: 1rem;
justify-self: center;
}
button {
width: 80px;
height: 40px;
font-size: 1.2rem;
border: none;
border-radius: 2px;
background-color: #70a1ff;
color: #130f40;
cursor: pointer;
}
.item0,
.item7,
.item10,
.item13,
.item16 {
grid-column: 1;
}
.item1,
.item8,
.item11,
.item14,
.item17 {
grid-column: 2;
}
.item2,
.item9,
.item12,
.item15 {
grid-column: 3;
}
.item3,
.item4,
.item5,
.item6,
.item18 {
grid-column: 4;
}
.item18 button {
background-color: #eb4d4b;
color: #fff;
}
.item5 button,
.item3 button,
.item4 button,
.item6 button {
background-color: #4834d4;
color: #fff;
}
<div class="container">
<div class="output">
<h3>69</h3>
</div>
<div class="buttons">
<div class="item0">
<button>AC</button>
</div>
<div class="item1">
<button>C</button>
</div>
<div class="item2">
<button>%</button>
</div>
<div class="item3">
<button>÷</button>
</div>
<div class="item4">
<button>×</button>
</div>
<div class="item5">
<button>-</button>
</div>
<div class="item6">
<button>+</button>
</div>
<div class="item7">
<button>1</button>
</div>
<div class="item8">
<button>2</button>
</div>
<div class="item9">
<button>3</button>
</div>
<div class="item10">
<button>4</button>
</div>
<div class="item11">
<button>5</button>
</div>
<div class="item12">
<button>6</button>
</div>
<div class="item13">
<button>7</button>
</div>
<div class="item14">
<button>8</button>
</div>
<div class="item15">
<button>9</button>
</div>
<div class="item16">
<button>0</button>
</div>
<div class="item17">
<button>.</button>
</div>
<div class="item18">
<button>=</button>
</div>
</div>
</div>
</div>

There is no reason to wrap every single button in a div. The whole reason to use a grid in the first place is to not hard-code everything HTML-wise but only apply the grid to the container. Simply create a 4-column grid (grid-template-columns: repeat(4, 1fr) and let the "equal" button span 2 columns:
.container {
height: 500px;
width: 400px;
background-color: #3333;
border-radius: 10px;
}
.output {
height: 100px;
padding: 3rem 3rem 6rem 3rem;
font-size: 2.5rem;
text-align: right;
background-color: #eee;
border-radius: 10px;
}
.buttons {
width: 400px;
display: grid;
grid-gap: 2px;
grid-template-columns: repeat(4, 1fr);
}
button {
height: 40px;
font-size: 1.2rem;
border: none;
border-radius: 2px;
background-color: #70a1ff;
color: #130f40;
cursor: pointer;
}
.buttons button:last-child {
grid-column: span 2;
background-color: red;
}
<div class="container">
<div class="output">
<h3>69</h3>
</div>
<div class="buttons">
<button>AC</button>
<button>C</button>
<button>%</button>
<button>÷</button>
<button>×</button>
<button>-</button>
<button>+</button>
<button>1</button>
<button>2</button>
<button>3</button>
<button>4</button>
<button>5</button>
<button>6</button>
<button>7</button>
<button>8</button>
<button>9</button>
<button>0</button>
<button>.</button>
<button>=</button>
</div>
</div>

Related

Carousel moves upward as I slide down my window

I am working on one of my personal projects where I am designing a website for a restaurant using HTML and CSS.....I have got a code for a Carousel and I am trying to integrate it with my website....
But I am facing a problem with the carousel...As I slide down my window...the carousel also tends to move upward and doesn't stick to it's original position....How am i supposed to fix this issue....
This is the first one among all my personal projects.
I would be pleased and more than happy if the experts or members of this community would help me out in this process of learning and aid me in getting this project completed....
This is the project
This is my index.html.The code for Carousel is at the last section with the comment "Carousel Starts"
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Restaurant Page</title>
<link href="styles.css" rel="stylesheet" type="text/css" />
</head>
<body>
<nav>
<div class="navigation container">
<div class="logo_container">
<img src="images/logo.png" alt="logo" />
</div>
<div class="allmenus">
<ul>
<li class="menu">Home</li>
<li class="menu" >About Us</li>
<li class="menu" >Our Services</li>
</ul>
</div>
</nav>
<script
src="https://kit.fontawesome.com/8b6347e91f.js"
crossorigin="anonymous"
></script>
<!--First Section-->
<div class="container" >
<div class="first">
<div class="first_image">
<img src="images/hero_image.png" alt="Vegetables" />
</div>
<div class="first_content">
<div class="tag">50% Off On All Products</div>
<h1>Enjoy Your Delicious Food</h1>
<p>
Make reservations, hours, and locations front-and-center, and
prominently get your order within few minutes of getting placed
</p>
<button class="explore">Order Now</button>
</div>
</div>
<section class="second_section" >
<div class="feature">
<img src="images/discount 1.png" />
<div class="feature_content">
<h1>Discount Voucher</h1>
<p>Get a discount voucher worth Rs.100 on yout first order</p>
</div>
</div>
<div class="feature">
<img src="images/fresh.png" />
<div class="feature_content">
<h1>Fresh Healthy Food</h1>
<p>Get a discount voucher worth Rs.100 on yout first order</p>
</div>
</div>
<div class="feature">
<img src="images/delivery.png" />
<div class="feature_content">
<h1>Instant delivery</h1>
<p>Get a discount voucher worth Rs.100 on yout first order</p>
</div>
</div>
</section>
</div>
<!--Popular Dishes -->
<div class="container dishes" >
<h1 class="popdishes">Our Popular Dishes</h1>
<div class="subcontainer">
<div class="section">
<img class="dish" src="images/dish-3.png" alt="">
<h2 class="recipe">Chicken Leg Piece</h2>
<div class="priceandbutton">
<span>$15</span>
<button class="addtocart">Add To Cart</button>
</div>
</div>
<div class="section">
<img class="dish" src="images/dish-1.png" alt="">
<h2 class="recipe">Burger</h2>
<div class="priceandbutton">
<span>$20</span>
<button class="addtocart">Add To Cart</button>
</div>
</div>
<div class="section">
<img class="dish" src="images/dish-2.png" alt="">
<h2 class="recipe">Chicken Nuggets</h2>
<div class="priceandbutton">
<span>$12</span>
<button class="addtocart">Add To Cart</button>
</div>
</div>
</div>
<!-- Second SubContainer Starts-->
<div class="subcontainer">
<div class="section">
<img class="dish" src="images/dish-4.png" alt="">
<h2 class="recipe">Pizza</h2>
<div class="priceandbutton">
<span>$12</span>
<button class="addtocart">Add To Cart</button>
</div>
</div>
<div class="section">
<img class="dish" src="images/dish-5.png" alt="">
<h2 class="recipe">Chocolate Cookies</h2>
<div class="priceandbutton">
<span>$15</span>
<button class="addtocart">Add To Cart</button>
</div>
</div>
<div class="section">
<img class="dish" src="images/dish-6.png" alt="">
<h2 class="recipe">Broasted</h2>
<div class="priceandbutton">
<span>$20</span>
<button class="addtocart">Add To Cart</button>
</div>
</div>
</div>
<!-- Third SubContainer Starts-->
<div class="subcontainer">
<div class="section">
<img class="dish" src="images/menu-33 new.jpg" alt="">
<h2 class="recipe">Crepes</h2>
<div class="priceandbutton">
<span>$12</span>
<button class="addtocart">Add To Cart</button>
</div>
</div>
<div class="section">
<img class="dish" src="images/menu-44.jpg" alt="">
<h2 class="recipe">Waffles</h2>
<div class="priceandbutton">
<span>$15</span>
<button class="addtocart">Add To Cart</button>
</div>
</div>
<div class="section">
<img class="dish" src="images/menu-55.jpg" alt="">
<h2 class="recipe">Pasteries</h2>
<div class="priceandbutton">
<span>$20</span>
<button class="addtocart">Add To Cart</button>
</div>
</div>
</div>
</div>
<!-- Carousel Starts -->
<div class="container">
<div class="mycarousel" >
<input type="radio" name="position" checked />
<input type="radio" name="position" />
<input type="radio" name="position" />
<input type="radio" name="position" />
<input type="radio" name="position" />
<main id="carousel">
<div class="item" >
<div class="reviews">
<img class="reviewimages" src="images/pic-1.png">
<div class="content">
<h1>John Doe</h1>
<p>In publishing and graphic design, Lorem ipsum is a placeholder text commonly used to demonstrate the visual form of a document or a typeface without relying on meaningful content. Lorem ipsum may be used as a placeholder before final copy is available.
</div>
</div>
</div>
<div class="item">
<div class="reviews">
<img class="reviewimages" src="images/pic-2.png">
<div class="content">
<h1>John Doe</h1>
<p>In publishing and graphic design, Lorem ipsum is a placeholder text commonly used to demonstrate the visual form of a document or a typeface without relying on meaningful content. Lorem ipsum may be used as a placeholder before final copy is available.
</div>
</div>
</div>
<div class="item">
<div class="reviews" >
<img class="reviewimages" src="images/pic-1.png">
<div class="content">
<h1>John Doe</h1>
<p>In publishing and graphic design, Lorem ipsum is a placeholder text commonly used to demonstrate the visual form of a document or a typeface without relying on meaningful content. Lorem ipsum may be used as a placeholder before final copy is available.
</div>
</div>
</div>
<div class="item">
<div class="reviews">
<img class="reviewimages" src="images/pic-1.png">
<div class="content">
<h1>John Doe</h1>
<p>In publishing and graphic design, Lorem ipsum is a placeholder text commonly used to demonstrate the visual form of a document or a typeface without relying on meaningful content. Lorem ipsum may be used as a placeholder before final copy is available.
</div>
</div>
</div>
<div class="item">
<div class="reviews">
<img class="reviewimages" src="images/pic-1.png">
<div class="content">
<h1>John Doe</h1>
<p>In publishing and graphic design, Lorem ipsum is a placeholder text commonly used to demonstrate the visual form of a document or a typeface without relying on meaningful content. Lorem ipsum may be used as a placeholder before final copy is available.
</div>
</div>
</div>
<main>
</div>
</div>
</body>
</html>
This is my css file
* {
margin: 0;
padding: 0;
box-sizing: border-box;
}
html,
body {
line-height: 1.4;
font-weight: 300;
font-family: "Roboto", sans-serif;
}
nav {
box-shadow: 5px 5px 5px rgba(1, 1, 1, 0.05);
background-color: white;
position: sticky;
top: 0;
margin-bottom: 32px;
padding: 10px;
}
.navigation {
display: flex;
justify-content: space-between;
align-items: center;
color: rgba(28, 22, 22, 0.414);
font-weight: bolder;
font-size: large;
}
.container {
max-width: 1200px;
margin: 0 auto;
}
ul {
text-align: right;
display: flex;
font-family: Helvetica, sans-serif;
font-weight: bolder;
list-style: none;
}
li {
padding: 0 20px;
margin-top: 30px;
}
li:hover {
color: #134a7a;
text-decoration: underline;
}
.logo_container {
margin-left: 15px;
}
/* First Section */
.first {
display: flex;
gap: 100px;
justify-content: center;
align-items: center;
}
.first_content {
display: flex;
flex-direction: column;
gap: 20px;
}
.tag {
background-color: #134a7a;
align-self: flex-start;
padding: 5px 10px;
color: white;
}
.first_content h1 {
font-size: 72px;
line-height: 1.2;
font-weight: 500;
}
button {
padding: 10px 15px;
color: white;
font-weight: 500;
font-size: 22px;
background: crimson;
border: none;
border-radius: 30px;
align-self: flex-start;
width: 250px;
}
button:hover {
transition: 0.2s ease-in-out;
background:#e5eaee;
color: #134a7a;
font-weight: 500;
}
.second_section {
display: flex;
flex-direction: row;
gap: 20px;
margin-top: 100px;
justify-content: center;
}
.feature {
display: flex;
flex-direction: row;
justify-content: center;
align-items: center;
gap: 15px;
height: 165px;
background-color: #134a7a;
color: azure;
}
.feature:hover {
transition: 0.2s ease-in-out;
background-color: azure;
color:#134a7a;
}
.dishes{
background-color: #e5eaee;
margin-top: 20px;
height:1250px;
margin-bottom: 20px;;
}
.dishes .subcontainer {
display: flex;
flex-direction: row;
justify-content: space-evenly;
gap: 25px;
}
.recipe{
font-weight: 300;
}
.section {
width: 350px;
height: 350px;
background: white;
padding-top: 32px;
margin-top: 25px;
}
.section{
display:flex;
flex-direction:column;
justify-content: center;
align-items: center;
gap: 10px;
}
h1.popdishes {
padding-top: 20px;
color:#134a7a;
text-align: center;
}
.priceandbutton {
display: flex;
flex-direction: row;
gap:10px
}
span {
padding-top: 5px;
font-weight: 400;
color:#134a7a;
font-size: 30px;
}
.addtocart{
padding: 10px 15px;
color: white;
font-weight: 500;
font-size: 22px;
background:#134a7a;
border: none;
border-radius: 30px;
align-self: flex-start;
width: 200px;
}
.addtocart:hover {
background:#e5eaee;
color: #134a7a;
font-weight: 500;
transition: 0.2s ease-in-out;
}
.reviewimages{
height:150px;
width:170px;
border-radius:50%;
}
.reviews{
display:flex;
flex-direction:column;
justify-content:center;
align-items:center;
padding:20px
}
.content{
text-align:center
}
.mycarousel{
height: 600px;
margin: 0;
display: grid;
grid-template-rows: 500px 100px;
grid-template-columns: 1fr 30px 30px 30px 30px 30px 1fr;
align-items: center;
justify-items: center;
background-color: #134a7a;
}
main#carousel {
grid-row: 1 / 2;
grid-column: 1 / 8;
width: 100vw;
height: 500px;
display: flex;
align-items: center;
justify-content: center;
overflow: hidden;
transform-style: preserve-3d;
perspective: 600px;
--items: 5;
--middle: 3;
--position: 1;
pointer-events: none;
}
div.item {
position: absolute;
width: 300px;
height: 400px;
background-color: coral;
--r: calc(var(--position) - var(--offset));
--abs: max(calc(var(--r) * -1), var(--r));
transition: all 0.25s linear;
transform: rotateY(calc(-10deg * var(--r)))
translateX(calc(-300px * var(--r)));
z-index: calc((var(--position) - var(--abs)));
overflow: hidden;
}
div.item:nth-of-type(1) {
--offset: 1;
}
div.item:nth-of-type(2) {
--offset: 2;
}
div.item:nth-of-type(3) {
--offset: 3;
}
div.item:nth-of-type(4) {
--offset: 4;
}
div.item:nth-of-type(5) {
--offset: 5;
}
input:nth-of-type(1) {
grid-column: 2 / 3;
grid-row: 2 / 3;
}
input:nth-of-type(1):checked ~ main#carousel {
--position: 1;
}
input:nth-of-type(2) {
grid-column: 3 / 4;
grid-row: 2 / 3;
}
input:nth-of-type(2):checked ~ main#carousel {
--position: 2;
}
input:nth-of-type(3) {
grid-column: 4 /5;
grid-row: 2 / 3;
}
input:nth-of-type(3):checked ~ main#carousel {
--position: 3;
}
input:nth-of-type(4) {
grid-column: 5 / 6;
grid-row: 2 / 3;
}
input:nth-of-type(4):checked ~ main#carousel {
--position: 4;
}
input:nth-of-type(5) {
grid-column: 6 / 7;
grid-row: 2 / 3;
}
input:nth-of-type(5):checked ~ main#carousel {
--position: 5;
}
.reviewimages{
height:150px;
width:170px;
border-radius:50%;
border:5px solid black;
}
.content h1{
color:#134a7a;
}
.reviews{
display:flex;
flex-direction:column;
justify-content:center;
align-items:center;
padding:20px
}
.content{
text-align:center
}
.mycarousel{
height: 600px;
margin: 0;
display: grid;
grid-template-rows: 500px 100px;
grid-template-columns: 1fr 30px 30px 30px 30px 30px 1fr;
align-items: center;
justify-items: center;
}
main#carousel {
grid-row: 1 / 2;
grid-column: 1 / 8;
width: 100vw;
height: 500px;
display: flex;
align-items: center;
justify-content: center;
overflow: hidden;
transform-style: preserve-3d;
perspective: 600px;
--items: 5;
--middle: 3;
--position: 1;
pointer-events: none;
}
div.item {
position: absolute;
width: 300px;
height: 400px;
background-color: coral;
--r: calc(var(--position) - var(--offset));
--abs: max(calc(var(--r) * -1), var(--r));
transition: all 0.25s linear;
transform: rotateY(calc(-10deg * var(--r)))
translateX(calc(-300px * var(--r)));
z-index: calc((var(--position) - var(--abs)));
}
div.item:nth-of-type(1) {
--offset: 1;
background-color: #e5eaee;
}
div.item:nth-of-type(2) {
--offset: 2;
background-color: #e5eaee;
}
div.item:nth-of-type(3) {
--offset: 3;
background-color: #e5eaee;
}
div.item:nth-of-type(4) {
--offset: 4;
background-color: #e5eaee;
}
div.item:nth-of-type(5) {
--offset: 5;
background-color: #e5eaee;
}
input:nth-of-type(1) {
grid-column: 2 / 3;
grid-row: 2 / 3;
}
input:nth-of-type(1):checked ~ main#carousel {
--position: 1;
}
input:nth-of-type(2) {
grid-column: 3 / 4;
grid-row: 2 / 3;
}
input:nth-of-type(2):checked ~ main#carousel {
--position: 2;
}
input:nth-of-type(3) {
grid-column: 4 /5;
grid-row: 2 / 3;
}
input:nth-of-type(3):checked ~ main#carousel {
--position: 3;
}
input:nth-of-type(4) {
grid-column: 5 / 6;
grid-row: 2 / 3;
}
input:nth-of-type(4):checked ~ main#carousel {
--position: 4;
}
input:nth-of-type(5) {
grid-column: 6 / 7;
grid-row: 2 / 3;
}
input:nth-of-type(5):checked ~ main#carousel {
--position: 5;
}
Try adding justify-content: space-around; so it stays the same width as the page:
.mycarousel {
height: 600px;
margin: 0;
display: grid;
grid-template-rows: 500px 100px;
grid-template-columns: 1fr 30px 30px 30px 30px 30px 1fr;
align-items: center;
justify-items: center;
justify-content: space-around;
}
For the slide part, I see it goes over the navbar you can solve it by adding a z-index: 1; to the navbar.
nav {
box-shadow: 5px 5px 5px rgb(1 1 1 / 5%);
background-color: white;
position: sticky;
top: 0;
margin-bottom: 32px;
padding: 10px;
z-index: 1;
}

Running a jQuery function on separate classes

I have some HTML elements, that all have the same markup. Each div does have a unique parent class.
So when I try to write some jQuery to target each element individually it triggers on all instances regardless of whether I specify which class to target. My thinking was by using (this) it would only target stuff inside of the div 'box__wrapper--before'.
Does anyone know where I am going wrong?
$('.box__wrapper--before').each(function() {
$(this).find('.box__random').insertBefore('.box__item:nth-child(3');
});
html {
box-sizing: border-box;
font-size: 62.5%;
}
*,
*:before,
*:after {
box-sizing: inherit;
}
body {
background: #282828;
color: white;
font-family: "Montserrat", sans-serif;
font-size: 1.6rem;
font-weight: 500;
line-height: 1;
margin: 0;
}
h1 {
color: white;
font-size: 20px;
font-weight: 600;
margin-bottom: 20px;
margin-top: 0;
}
.box__wrapper {
color: #111;
padding-bottom: 20px;
padding-top: 20px;
}
.box__wrapper:nth-child(odd) {
background: green;
}
.box__wrapper:nth-child(even) {
background: blue;
}
.box__container {
margin-left: auto;
margin-right: auto;
max-width: 1200px;
}
.box__flex__wrapper {
display: flex;
justify-content: center;
margin-left: -60px;
}
.box__item {
padding-left: 60px;
flex-basis: 20%;
max-width: 20%;
}
.box__item span {
align-items: center;
border: 4px solid white;
border-radius: 100px;
display: flex;
height: 60px;
justify-content: center;
}
.box__one span,
.box__three span {
background: #58b2eb;
}
.box__two span,
.box__four span {
background: #ffa770;
}
.box__random span {
background: #7fd28c;
}
.prod__cta__msg {
background: red;
bottom: 0;
position: absolute;
width: 100%;
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<section class="box__wrapper box__wrapper--before">
<div class="box__container">
<div class="box__flex__wrapper">
<div class="box__item box__one">
<span>Div One</span>
</div>
<div class="box__item box__two">
<span>Div Two</span>
</div>
<div class="box__item box__three">
<span>Div Three</span>
</div>
<div class="box__item box__four">
<span>Div Four</span>
</div>
<div class="box__item box__random">
<span>Dynamic Div 1</span>
</div>
</div>
</div>
</section>
<section class="box__wrapper box__wrapper--after">
<div class="box__container">
<div class="box__flex__wrapper">
<div class="box__item box__one">
<span>Div One</span>
</div>
<div class="box__item box__two">
<span>Div Two</span>
</div>
<div class="box__item box__three">
<span>Div Three</span>
</div>
<div class="box__item box__four">
<span>Div Four</span>
</div>
<div class="box__item box__random">
<span>Dynamic Div 2</span>
</div>
</div>
</div>
</section>
Codepen Example: https://codepen.io/nickelse/pen/MWbdvPw
The issue is with:
.insertBefore('.box__item:nth-child(3)')
which appends the box_random into all sections.
The .insertBefore can take a jquery object (not just a string selector) which specifies the insertion point, so you can use this to find only the relevant nth-child:
$('.box__wrapper--before').each(function() {
var third = $('.box__item:nth-child(3)', this);
$(this).find('.box__random').insertBefore(third);
});
(variable not required, shown for clarity)
The original could have been written as:
$('.box__wrapper--before').each(function() {
var third = $('.box__item:nth-child(3)');
$(this).find('.box__random').insertBefore(third);
});
where you can see that
var third = $('.box__item:nth-child(3)');
selects all items across all parents - so needs that specificity added.
Giving an updated snippet below. Here the box__random in the 2nd div is not moved because it's not in .box__wrapper--before.
$('.box__wrapper--before').each(function() {
$(this).find('.box__random').insertBefore($('.box__item:nth-child(3)', this));
});
html {
box-sizing: border-box;
font-size: 62.5%;
}
*,
*:before,
*:after {
box-sizing: inherit;
}
body {
background: #282828;
color: white;
font-family: "Montserrat", sans-serif;
font-size: 1.6rem;
font-weight: 500;
line-height: 1;
margin: 0;
}
h1 {
color: white;
font-size: 20px;
font-weight: 600;
margin-bottom: 20px;
margin-top: 0;
}
.box__wrapper {
color: #111;
padding-bottom: 20px;
padding-top: 20px;
}
.box__wrapper:nth-child(odd) {
background: green;
}
.box__wrapper:nth-child(even) {
background: blue;
}
.box__container {
margin-left: auto;
margin-right: auto;
max-width: 1200px;
}
.box__flex__wrapper {
display: flex;
justify-content: center;
margin-left: -60px;
}
.box__item {
padding-left: 60px;
flex-basis: 20%;
max-width: 20%;
}
.box__item span {
align-items: center;
border: 4px solid white;
border-radius: 100px;
display: flex;
height: 60px;
justify-content: center;
}
.box__one span,
.box__three span {
background: #58b2eb;
}
.box__two span,
.box__four span {
background: #ffa770;
}
.box__random span {
background: #7fd28c;
}
.prod__cta__msg {
background: red;
bottom: 0;
position: absolute;
width: 100%;
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<section class="box__wrapper box__wrapper--before">
<div class="box__container">
<div class="box__flex__wrapper">
<div class="box__item box__one">
<span>Div One</span>
</div>
<div class="box__item box__two">
<span>Div Two</span>
</div>
<div class="box__item box__three">
<span>Div Three</span>
</div>
<div class="box__item box__four">
<span>Div Four</span>
</div>
<div class="box__item box__random">
<span>Dynamic Div 1</span>
</div>
</div>
</div>
</section>
<section class="box__wrapper box__wrapper--after">
<div class="box__container">
<div class="box__flex__wrapper">
<div class="box__item box__one">
<span>Div One</span>
</div>
<div class="box__item box__two">
<span>Div Two</span>
</div>
<div class="box__item box__three">
<span>Div Three</span>
</div>
<div class="box__item box__four">
<span>Div Four</span>
</div>
<div class="box__item box__random">
<span>Dynamic Div 2</span>
</div>
</div>
</div>
</section>

CSS - How to position this "menu" like on the UI design that I have made in Figma?

As you can see from the title I want to know how to position this menu that I will show to you like on this UI design that I have made.
Here is the examples:
And here is how I tried to do it.
This is the code so far:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="stylesheet" href="styles.css">
<link href="https://fonts.googleapis.com/css2?family=Inter:wght#300&display=swap" rel="stylesheet">
<title>Document</title>
</head>
<body>
<div class="root flexbox">
<div class="navbar flexbox">
<div class="container flexbox align-center">
<img src="Slike/logo-avion.png" alt="">
<div class="right-column flexbox align-center">
<div class="navbar__navigation">
Početna
Destinacija
O nama
Partner
</div>
<div class="order-btn flexbox align-center">
Prijavi se!
</div>
<div class="konj flexbox align-center">
Registriraj se!
</div>
</div>
</div>
</div>
<div class="content">
<div class="container flexbox">
<div class="content__left_column">
<h2>Ostvarite svoje
putovanje iz snova!</h2>
<p>Potraži svoj odmor na pravom mjestu!</p>
<div class="linija">
<span class="linija crna-linija"></span>
</div>
<div class="kvadrati">
<div class="kvadrati prvi flexbox align-center ">
<p>Lokacija</p>
<img src="Slike/Vector.png" alt="">
</div>
<div class="kvadrati drugi flexbox align-center ">
<p>Aktivnost</p>
<img src="Slike/Vector.png" alt="">
</div>
<div class="kvadrati treci flexbox align-center ">
<p>Ocjena</p>
<img src="Slike/Vector.png" alt="">
</div>
<div class="kvadrati cetvrti flexbox align-center">
<p>Datum</p>
<img src="Slike/Vector.png" alt="">
</div>
</div>
</div>
<div class="content__right_column">
<img src="Slike/template_3_-_copy_dribble1dribble_1.png" alt="">
</div>
</div>
</div>
</div>
</body>
</html>
The div class kvadrati is used to make this menu. I know this may seem complicated to describe but I hope you know what I meant by asking this question. I tried using flexbox display and grid still failed. I am not a beginner in CSS but clearly this is something that I have a problem with.
Here is the CSS code:
.prvi {
width: 22rem;
height: 5.2rem;
border-radius: 0.6rem;
border: 0.1rem solid #afb0b9;
}
EDIT: Here is all of the styles.css
html {
font-size: 10px;
}
* {
margin: 0;
padding: 0;
font-family: Inter;
}
.right-column {
margin-left: auto;
}
body {
background-color: #ffffff;
line-height: 3rem;
}
.container {
width: 1300px;
margin: auto;
}
.root {
font-size: 1.2rem;
flex-direction: column;
min-height: 100%;
}
.flexbox {
display: flex;
}
.align-center {
align-items: center;
}
a {
text-decoration: none;
}
html, body {
height: 100%;
}
.navbar {
margin-top: 20px;
}
.navbar__navigation a {
color: #b8becd;
display: inline-flex;
font-size: 1.5rem;
font-weight: 400;
margin-right: 20px;
}
.order-btn {
height: 4.4rem;
margin-left: 50px;
border-radius: 0.8rem;
border: 0.1rem solid #57d2a3;
margin-right: 15px;
}
.order-btn a {
padding: 21px 24px;
}
.navbar__navigation .active {
color: #202336;
}
.konj {
height: 4.4rem;
border-radius: 0.8rem;
background-color: #57d2a3;
}
.konj a {
color: #ffffff;
padding: 21px 24px;
}
.content__left_column {
margin-left: 20px;
margin-top: 200px;
}
.content__right_column {
margin-top: 90px;
margin-left: auto;
}
.content__left_column h2 {
width: 55.9rem;
color: #202336;
font-family: "Playfair Display";
font-size: 6.4rem;
font-weight: 700;
line-height: 8rem;
}
.content__left_column p {
margin-top: 69px;
width: 40rem;
color: #202336;
font-size: 2.2rem;
font-weight: 400;
}
.linija {
margin-top: 21px;
width: 3.2rem;
height: 0.3rem;
border-radius: 0.4rem;
background-color: #202336;
}
.kvadrati {
margin-top: 20px;
display: grid;
grid-template: 70px 70px / 226px 226px;
width: 226px;
height: 52px;
grid-gap: 20px;
padding: 16px;
}
.kvadrati div {
border-radius: 10px;
border: 1px solid gray;
}
A couple issues with your code
<div class="kvadrati">
<div class="kvadrati prvi flexbox align-center ">
<p>Lokacija</p>
<img src="Slike/Vector.png" alt="">
</div>
<div class="kvadrati drugi flexbox align-center ">
<p>Aktivnost</p>
<img src="Slike/Vector.png" alt="">
</div>
<div class="kvadrati treci flexbox align-center ">
<p>Ocjena</p>
<img src="Slike/Vector.png" alt="">
</div>
<div class="kvadrati cetvrti flexbox align-center">
<p>Datum</p>
<img src="Slike/Vector.png" alt="">
</div>
</div>
As you can see both the grid div <div class="kvadrati"> and the items <div class="kvadrati drugi flexbox align-center "> share the same class kvadrati. As a result they both create a 2x2 grid. You should remove the kvadrati class on the 4 grid items.
.content__left_column p {
margin-top: 69px;
width: 40rem;
color: #202336;
font-size: 2.2rem;
font-weight: 400;
}
And in this part of the code you give the <p> elements a margin-top: 69px;. This causes the <p> Items in your grid to move down 69 pixels. You could change <p>Potraži svoj odmor na pravom mjestu!</p> to a <h3> style it using a class so it doesn't affect the other <p> elements.
Alternatively, since you probably want a dropdown list, you can avoid this by using <select> tags instead. See here for a guide on creating a custom select.
-----------
Here is a simple example on how to use a grid to create a 2x2.
If you need more information on how to use css grid, read on w3schools or MDN
body {
margin: 0;
height: 80vh;
width: 80vw;
}
.grid {
display: grid;
grid-template: 1fr 1fr / 1fr 1fr;
width: 100%;
height: 100%;
grid-gap: 16px;
padding: 16px;
}
.grid div {
border-radius: 10px;
border: 1px solid gray;
}
<div class="grid">
<div></div>
<div></div>
<div></div>
<div></div>
</div>

Need help getting the correct layout

I have some problems laying out my elements. I tried to achieve the following layout in my web application:
I tried to use div´s and style them but it looks like this when I run it
I wanted to create a grid with three container in each row. Also for responsiveness I used flexbox.
Any suggestions how the layout could improve? I think I messed it up a little.
.contacts-container {
display: flex;
flex-wrap: wrap;
justify-content: space-around;
}
h1.subheading {
color: red;
}
.contact {
flex: 0 0 32%;
/* don't grow, don't shrink, width */
margin-bottom: 5px;
border: 1px solid #ddd;
}
.contact a {
color: black;
text-decoration: none;
}
.contactInfo {
padding: 1.4em;
float: left;
}
.contactInfo h2 {
margin-top: 0;
margin-bottom: 0.5em;
font-weight: normal;
}
.contactInfo p {
font-size: 95%;
}
.contactInfo .contactName {
float: right;
}
.contactDetails {
float: left;
}
.contactDetails img {
width: 50px;
height: 50px;
}
#contact .contact-buttons {
position: absolute;
bottom: 0;
left: 0;
}
/* Using flexbox with media queries to make the layout responsive*/
#media screen and (min-width: 40em) {
.contacts-container {
display: flex;
flex-wrap: wrap;
justify-content: space-between;
margin-top: -1em;
}
.contact-info {
display: flex;
flex: 0 1 calc(50% - 0.5em);
margin-bottom: 1em;
}
}
#media screen and (min-width: 60em) {
.contacts-container {
margin-top: inherit;
}
.contact-info {
flex: 0 1 calc(33% - 1em);
margin-bottom: 2em;
}
}
<div class="contacts">
<h1 class="subheading">Deine Kontakte</h1>
<div class="contacts-container">
<div v-for="contact in contacts" class="contact" :key="contact.name">
<div class="contactInfo">
<img :src="getImage(contactImg)" />
<div class="contactName">
<p>Prename Surname</p>
<p>City</p>
<p>Country</p>
</div>
</div>
<div class="contactDetails">
<div>
<img :src="getImage(contactImg)" style="" /> test#test.com
</div>
<div>
<img :src="getImage(contactImg)" /> test#test.com
</div>
<div>
<img :src="getImage(contactImg)" /> test#test.com
</div>
</div>
<div class="contact-buttons">
<button v-on:click="counter += 1">Add 1</button>
<button v-on:click="counter += 1">Add 1</button>
</div>
</div>
</div>
</div>
.contacts {
width: 300px;
padding: 40px;
border: 1px solid black;
}
.contact {
display: flex;
flex-wrap: wrap;
flex-direction: column;
}
.contact .contactInfo {
display: flex;
margin-bottom: 30px;
}
.contact .contactInfo img {}
.contact .contactInfo .contactName {
margin: auto 0;
margin-left: 30px;
}
.contact .contactDetails {
margin-bottom: 30px;
border: 1px solid black;
}
.contact .contactDetails div {
display: flex;
margin: 10px;
}
.contact .contactDetails div p {
margin-left: 30px;
}
.contact .contact-buttons {
width: 100%;
display: flex;
justify-content: space-between;
}
<div class="contacts">
<h1 class="subheading">Deine Kontakte</h1>
<div class="contacts-container">
<div v-for="contact in contacts" class="contact" :key="contact.name">
<div class="contactInfo">
<img src="https://via.placeholder.com/150" />
<div class="contactName">
<p>Prename Surname</p>
<p>City</p>
<p>Country</p>
</div>
</div>
<div class="contactDetails">
<div>
<img src="https://via.placeholder.com/50" />
<p>test#test.com</p>
</div>
<div>
<img src="https://via.placeholder.com/50" />
<p>test#test.com</p>
</div>
<div>
<img src="https://via.placeholder.com/50" />
<p>test#test.com</p>
</div>
</div>
<div class="contact-buttons">
<button v-on:click="counter += 1">Add 1</button>
<button v-on:click="counter += 1">Add 1</button>
</div>
</div>
</div>
</div>
.contact {
margin-bottom: 5px;
border: 1px solid #ddd;
padding: 10px;
}
.contactInfo {
display: flex;
align-items: center;
}
.contactDetails {
border: 1px solid #ddd;
padding: 10px;
}
.contactDetailsRow {
display: flex;
flex-wrap: nowrap;
align-items: center;
}
.contactName,
.contactDetailsRowName {
flex: 1;
padding-left: 10px;
}
.contact-buttons {
display: flex;
}
.contact-buttons > button {
flex: 1;
margin: 10px;
}
<div class="contact">
<div class="contactInfo">
<div>
<img src="https://via.placeholder.com/100" />
</div>
<div class="contactName">
<h5>Prename Surname</h5>
<p>City</p>
<p>Country</p>
</div>
</div>
<div class="contactDetails">
<div class="contactDetailsRow">
<div>
<img src="https://via.placeholder.com/50"/>
</div>
<div class="contactDetailsRowName">
test#test.com
</div>
</div>
<div class="contactDetailsRow">
<div>
<img src="https://via.placeholder.com/50"/>
</div>
<div class="contactDetailsRowName">
test#test.com
</div>
</div>
<div class="contactDetailsRow">
<div>
<img src="https://via.placeholder.com/50"/>
</div>
<div class="contactDetailsRowName">
test#test.com
</div>
</div>
</div>
<div class="contact-buttons">
<button>Add 1</button>
<button>Add 1</button>
</div>
</div>
Been a while but something like this?
:root {
--baseMargin: 1.4em;
--buttonBorderRadius: 0.5em 0.5em 0.5em 0.5em;
--paddingBaseFill: calc(var(--baseMargin) * 2);
}
.contactInfo img {
min-width: 10em;
}
.contacts-container {
display: flex;
flex-direction: column;
flex-wrap: wrap;
justify-content: space-around;
}
h1.subheading {
color: red;
}
.contact {
flex: 0 1;
display: flex;
flex-direction: column;
/* don't grow, don't shrink, width */
margin-bottom: 5px;
border: 1px solid #ddd;
}
.wrapper {
margin: 0 var(--baseMargin);
}
.contact a {
color: black;
text-decoration: none;
}
.contactInfo {
flex: 1 1;
display: flex;
padding: var(--paddingBaseFill) 0;
}
.contactInfo h2 {
margin-top: 0;
margin-bottom: 0.5em;
font-weight: normal;
}
.contactInfo p {
font-size: 95%;
}
.contactInfo .contactName {
flex: 1 1;
margin-left: var(--baseMargin);
text-align: center;
}
.contactDetails {
flex: 1 1;
padding: 1em;
border: 0.1em solid black;
}
.contactDetails div {
display: flex;
align-items: center;
}
.contactDetails img {
width: 50px;
height: 50px;
padding: 0.5em;
}
.contact-buttons {
flex: 1 1;
display: flex;
justify-content: space-between;
padding: var(--baseMargin) 0;
}
.contact-buttons button {
font-size: 1.2em;
background: #018bff;
border-radius: var(--buttonBorderRadius);
padding: 0.25em;
color: #fff;
}
<div class="contacts">
<h1 class="subheading">Deine Kontakte</h1>
<div class="contacts-container">
<div v-for="contact in contacts" class="contact" :key="contact.name">
<div class="contactInfo wrapper">
<img :src="getImage(contactImg)" />
<div class="contactName">
<p>Prename Surname</p>
<p>City</p>
<p>Country</p>
</div>
</div>
<div class="contactDetails wrapper">
<div>
<img :src="getImage(contactImg)" style="" /> test#test.com
</div>
<div>
<img :src="getImage(contactImg)" /> test#test.com
</div>
<div>
<img :src="getImage(contactImg)" /> test#test.com
</div>
</div>
<div class="contact-buttons wrapper">
<button v-on:click="counter += 1">Add 1</button>
<button v-on:click="counter += 1">Add 1</button>
</div>
</div>
</div>
</div>

css flexbox grid masonry style

I've been trying to achieve the following layout using CSS and Flexbox but without any luck. Maybe someone here could help me out and point me the mistakes I've made and even suggest me the best course to do it.
This should be the final result (having all items different heights and widths but I'm starting to think that flexbox is not the best choice to do it):
Live example: https://jsfiddle.net/bogdaniel/Lzugkva3/5/
<div class="container">
<div class="blog-container">
<div class="blog-item" style="height: 286px;">
<div class="blog-post">
<div class="post-body">
<div class="post-title">
<h2>Item One</h2>
<span>height: 286px;</span>
<p>Item Should Be First In The List On The Left Column</p>
</div>
</div>
</div>
</div>
<div class="blog-item" style=";height: 203px;">
<div class="blog-post">
<div class="post-body">
<div class="post-title">
<h2>Item Two</h2>
<span>height: 203px;</span>
<p>Item Should Go To The right next to the height 286px;</p>
</div>
</div>
</div>
</div>
<div class="blog-item" style="height: 255px;">
<div class="blog-post">
<div class="post-body">
<div class="post-title">
<h2>Item Three</h2>
<span>height: 255px;</span>
<p>Item Should Be Second On the First Row In the List</p>
</div>
</div>
</div>
</div>
<div class="blog-item" style="height: 325px;">
<div class="blog-post">
<div class="post-body">
<div class="post-title">
<h2>Item Four</h2>
<span>height: 325px;</span>
<p>Item Should Go To The right Of Item Three On The Second Column</p>
</div>
</div>
</div>
</div>
<div class="blog-item" style="height: 251px;">
<div class="blog-post">
<div class="post-body">
<div class="post-title">
<h2>Item Five</h2>
<span>height: 251px;</span>
<span>width: 523px;</span> Item Should Start From The Left And Span 2 Columns Almost
</div>
</div>
</div>
</div>
<div class="blog-item" style="height: 282px;">
<div class="blog-post">
<div class="post-body">
<div class="post-title">
<h2>Item Six</h2>
<span>height: 282px;</span>
<span>width: 186px;</span>
<p>Item Should Be Portrait And Span On The Right Column</p>
</div>
</div>
</div>
</div>
<div class="blog-item" style=" width: 100%%; height: 204px;">
<div class="blog-post">
<div class="post-body">
<div class="post-title">
<h2>Item Seven</h2>
<span>height 204px;</span>
<span>with: 523px;</span>
</div>
</div>
</div>
</div>
<div class="blog-item" style="width: 186px; height: 174px;">
<div class="blog-post">
<div class="post-body">
<div class="post-title">
<h2>Item Eight</h2>
<span>height: 174px;</span>
<span>width: 186px;</span>
</div>
</div>
</div>
</div>
</div>
</div>
SCSS code:
.blog-container {
display: flex;
flex-flow: column wrap;
/* Your container needs a fixed height, and it
* needs to be taller than your tallest column. */
min-height: 1400px;
height: 100vh;
/* Force new columns */
&:before,
&:after {
content: "";
flex-basis: 100%;
width: 0;
order: 2;
}
/* Optional */
background-color: #f7f7f7;
border-radius: 3px;
margin: 15px auto;
counter-reset: items;
}
.blog-item {
width: 50%;
padding: 14px;
.blog-post {
height: 100%;
/* Optional */
position: relative;
border-radius: 3px;
border: 1px solid #4290e2;
box-shadow: 0 2px 2px rgba(0, 90, 250, 0.05),
0 4px 4px rgba(0, 90, 250, 0.05), 0 8px 8px rgba(0, 90, 250, 0.05),
0 16px 16px rgba(0, 90, 250, 0.05);
color: #000;
padding: 15px;
&:before {
counter-increment: items;
content: counter(items);
}
.post-body {
padding: 15px;
}
}
}
.blog-item:nth-child(2n + 1) {
order: 1;
}
.blog-item:nth-child(2n + 2) {
order: 2;
}
.blog-item:nth-child(2n + 3) {
order: 1;
}
.blog-item:nth-child(2n + 4) {
order: 2;
}
while waiting for a comment, if the layout is to be like the image, then you can use grid and set ahead amount of rows and cells to span for each element.
useful ressource : https://css-tricks.com/snippets/css/complete-guide-grid/ & https://gridbyexample.com/
body {
display: grid;
grid-template-columns: repeat(4, 1fr);
grid-template-rows: repeat(6, auto);
}
div:nth-child(1) {
grid-row: span 2;
}
div:nth-child(2) {
grid-column: span 3;
}
div:nth-child(3) {
grid-row: 3
}
div:nth-child(4) {
grid-column: span 3;
grid-row: span 2;
}
div:nth-child(5) {
grid-column: span 3;
}
div:nth-child(6) {
grid-row: span 2
}
div:nth-child(7) {
grid-column: span 3;
grid-row: span 2
}
/* makup */
body {
counter-reset: divs;
background: rgb(236, 244, 175);
}
div:before {
counter-increment: divs;
content: counter(divs);
background: tomato;
width: 1.2em;
height: 1.2em;
border-radius: 50%;
text-align: center;
color: green;
text-shadow: 0 0 3px white;
box-shadow: 0 0 3px;
}
div {
border-radius: 3px;
border: 1px solid darkblue;
background: lightblue;
}
body {
margin: 0;
grid-gap: 2vh;
padding: 2vh;
min-height: 100vh;
box-sizing: border-box;
}
div {
display: flex;
align-items: center;
justify-content: center;
font-size: calc(8px + 1.5vh + 1.5vw)
}
<div></div>
<div></div>
<div></div>
<div></div>
<div></div>
<div></div>
<div></div>
<div></div>
here is a codepen to test and play with (resize/add content, ... )