Prevent text from moving when resizing css - html

With a colleague of mine, we wanted to run a behavioural experiment that involve a fake purchase of virtual goods on a shop webpage. We designed the experiment on OTree (so on Python), but we needed Django and especially some html/css code to correctly place the images and texts on the webpage.
We managed to place the images and text as we wanted, to get something like that (the blue squares are just placeholders for the images):
The problem is that as soon as we change the window size, all the images and text just move on their own.
Here's a part of the code (not including everything because for now, we're just trying to get first the text in place and to understand the logic of it).
Here's the CSS:
<style>
body {
background-image: url('https://i.imgur.com/lVtlHWx.png');
background-repeat: no-repeat;
background-attachment: fixed;
background-size: 100% 100%;
}
</style>
and the HTML:
<div style="top: 99px; left: 99px;position: absolute; z-index: 1;visibility: visible;">
<h1 style="position: relative; color: #f0f0f0; font-family: Papyrus,monospace;">Welcome to the shop</h1>
<h3 style="position: relative;color: #f0f0f0; font-family: Papyrus,monospace;">Round 1/10</h3>
<p style="position: relative;top:9.5cm; left:6.5cm; color: #f0f0f0; font-family: Papyrus,monospace;font-size:25px;">5 Rubis</p>
<p style="position: relative;top:9.5cm; left:18cm; color: #f0f0f0; font-family: Papyrus,monospace;font-size:25px;">15 Rubis</p>
<p style="position: relative;top:9.5cm; left:29.5cm; color: #f0f0f0; font-family: Papyrus,monospace;font-size:25px;">25 Rubis</p>
<p style="position: relative;top:9.5cm; left:41cm; color: #f0f0f0; font-family: Papyrus,monospace;font-size:25px;">50 Rubis</p>
<p style="position: relative;top:16cm; left:6.5cm; color: #f0f0f0; font-family: Papyrus,monospace;font-size:25px;">5 Rubis</p>
<p style="position: relative;top:9.5cm; left:18cm; color: #f0f0f0; font-family: Papyrus,monospace;font-size:25px;">15 Rubis</p>
<p style="position: relative;top:9.5cm; left:29.5cm; color: #f0f0f0; font-family: Papyrus,monospace;font-size:25px;">25 Rubis</p>
<p style="position: relative;top:9.5cm; left:41cm; color: #f0f0f0; font-family: Papyrus,monospace;font-size:25px;">50 Rubis</p>
We're complete beginners in HTML/CSS and I think we bite more than we could chew. I followed and tried some answers but nothing really helped to resize every element with respect to the window size. Perhaps it is due to positioning the text? I still struggle to really understand how css places elements when their position are absolute or relative. We are in dire need of help on this matter, and would be immensely grateful if someone could solve our issue.

This is a typical case where using a table or better, CSS grid positioning would save you a lot of headaches.
Positioning according to measurements on your background image gives the following:
:root {
--display-scale: .5;
}
body {
padding: 10px;
background: black;
overflow: hidden; /* disable scrolling */
}
.wrapper {
transform: scale(var(--display-scale));
-webkit-transform: scale(var(--display-scale));
transform-origin: 0 0;
width: 1884px;
height: 1076px;
background: url('https://i.imgur.com/lVtlHWx.png') no-repeat;
position: relative;
font-family: Papyrus, monospace;
color: #f0f0f0;
}
.wrapper * {
box-sizing: border-box;
}
.wrapper h1 {
position: absolute;
padding: 0;
top: 10px;
left: 10px;
font-size: 48px;
}
.wrapper h3 {
position: absolute;
padding: 0;
top: 10px;
right: 10px;
font-size: 36px;
}
.wrapper .wallet {
position: absolute;
top: 42px;
height: 46px;
left: 720px;
right: 682px;
font-size: 36px;
display: flex;
align-items: center;
justify-content: center;
}
.wrapper .my-grid {
position: absolute;
/*background: #ff000055;*/
top: 228px;
left: 110px;
right: 82px;
bottom: 82px;
padding: 0;
column-gap: 38px;
display: grid;
grid-template-columns: 384px 402px 406px 1fr;
grid-template-rows: 196px 50px 202px 50px 202px 50px;
grid-auto-flow: column;
}
.my-grid .prod-image {
/*background: #00ff0055;*/
display: flex;
align-items: center;
justify-content: center;
}
.my-grid img {
display: block;
width: 180px;
height: 130px;
background: #5555ff;
outline: 5px solid black;
}
.my-grid .price {
/*background: #0000ff55;*/
font-size: 24px;
margin 0;
padding: 0;
display: flex;
align-items: center;
justify-content: center;
}
<div class="wrapper">
<h1>Welcome to the shop</h1>
<h3>Round 1/10</h3>
<p class="wallet">You have 1000 tokens</p>
<div class="my-grid">
<div class="prod-image"><img class="pic" /></div>
<p class="price">5 Rubis</p>
<div class="prod-image"><img class="pic" /></div>
<p class="price">15 Rubis</p>
<div class="prod-image"><img class="pic" /></div>
<p class="price">25 Rubis</p>
<div class="prod-image"><img class="pic" /></div>
<p class="price">50 Rubis</p>
<div class="prod-image"><img class="pic" /></div>
<p class="price">5 Rubis</p>
<div class="prod-image"><img class="pic" /></div>
<p class="price">15 Rubis</p>
<div class="prod-image"><img class="pic" /></div>
<p class="price">25 Rubis</p>
<div class="prod-image"><img class="pic" /></div>
<p class="price">50 Rubis</p>
<div class="prod-image"><img class="pic" /></div>
<p class="price">50 Rubis</p>
<div class="prod-image"><img class="pic" /></div>
<p class="price">50 Rubis</p>
<div class="prod-image"><img class="pic" /></div>
<p class="price">50 Rubis</p>
<div class="prod-image"><img class="pic" /></div>
<p class="price">50 Rubis</p>
</div>
</div>
Use the --display-scale: .5 variable to adjust display size

You can achieve your desired results with css Grid and Flexbox.
This page content:
<body>
<div id="head">
<h1>Welcome to the shop</h1>
<h3>Round 1/10</h3>
</div>
<div id="labels_container">
<div class="item"><p class="label">5 Rubis</p></div>
<div class="item"><p class="label">15 Rubis</p></div>
<div class="item"><p class="label">25 Rubis</p></div>
<div class="item"><p class="label">50 Rubis</p></div>
<div class="item"><p class="label">5 Rubis</p></div>
<div class="item"><p class="label">15 Rubis</p></div>
<div class="item"><p class="label">25 Rubis</p></div>
<div class="item"><p class="label">50 Rubis</p></div>
<div class="item"><p class="label">5 Rubis</p></div>
<div class="item"><p class="label">15 Rubis</p></div>
<div class="item"><p class="label">25 Rubis</p></div>
<div class="item"><p class="label">50 Rubis</p></div>
</div>
</body>
With this css styling:
body {
background-image: url('./lVtlHWx.png');
background-repeat: no-repeat;
background-attachment: fixed;
background-size: 100% 100%;
display: grid;
grid-template-rows: [gstart]1fr[gmid] 5fr[gend];
height: 100vh;
width: 100vw;
}
#head {
grid-row: gstart / gmid;
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
}
#head * {
margin: 0;
}
#labels_container {
grid-row: gmid / gend;
margin-top: 3vh;
margin-left: 5vw;
margin-right: 7vw;
margin-bottom: 9.5vh;
display: grid;
grid-template-columns: repeat(4, 1fr);
grid-template-rows: repeat(3, 1fr);
column-gap: 2.5%;
}
.item .label {
margin: 0;
margin-bottom: 1vh;
}
* {
color: #f0f0f0;
font-family: Papyrus, monospace;
}
h1, h3 {
position: relative;
}
.item {
display: flex;
flex-direction: column;
align-items: center;
justify-content: flex-end;
}
.label {
font-size: 25px;
}
should do what you want.
Note: You might also find it beneficial to make the interface a div in your page with a constant aspect ratio, because you have an image as the backdrop for the entire interface. Having this image deform makes styling the page awkward. That being said, the styles above should work with your current setup.

I couldn't resist, here is what you should really do: abandon your backdrop that constrains layout, and use a real HTML layout instead, with textures to help achieving the effect you want.
This snippet should be viewed in full page mode
:root {
--iron-texture: url('https://www.outworldz.com/SeamlessTextures/master/Metal/iron_diffuse.png');
--wood-texture: url('https://images.designtrends.com/wp-content/uploads/2015/12/22092207/Seamless-Wooden-Floor-Texture.jpg?width=600');
}
html { padding: 0; margin: 0; height: 100%;}
body {
box-sizing: border-box;
padding: 1rem;
margin: 0;
min-height: 100%;
background: black;
color: white;
font-family: Papyrus, monospace;
font-size: 16px;
display: flex;
align-items: center;
justify-content: center;
}
.shop {
box-sizing: border-box;
width: 100%;
max-width: 1200px;
background: var(--wood-texture);
background-size: 30%;
color: #ccc;
padding: 1rem;
}
.shop header {
position: relative;
display: flex;
flex-direction: column;
gap: 1em;
}
.shop h1,
.shop p {
padding: 0;
margin: 0;
}
.shop h1 {
font-size: 32px;
}
.shop .round {
position: absolute;
top: 0;
right: 0;
font-size: 28px;
}
.iron-style {
background: var(--iron-texture);
border: 4px solid #1a1a1a;
border-top-color: #2a2a2a;
border-right-color: #2a2a2a;
}
.shop .wallet {
font-size: 20px;
font-weight: bold;
box-sizing: border-box;
width: 20em;
align-self: center;
text-align: center;
padding: .5em;
border-radius: 1.5em;
}
.shop main {
margin-top: 1rem;
padding-bottom: 1rem;
display: grid;
grid-template-columns: repeat(4, 1fr);
gap: 2rem 1rem;
border: 1rem solid #222;
border-image: var(--iron-texture);
border-image-repeat: round;
border-image-slice: 20;
box-shadow: inset -3px 3px 3px #111,
inset 3px -3px 5px #333;
}
.product {
display: flex;
flex-direction: column;
}
.pic-layout {
height: 100px;
min-width: 150px;
padding: 1rem;
display: flex;
align-items: center;
justify-content: center;
}
.pic-layout img {
max-width: 150px;
max-height: 100px;
background: #aaf;
outline: 5px solid #333;
}
.price {
width: 6em;
padding: .3em 1em;
border-radius: .5em;
align-self: center;
text-align: center;
}
#media screen and (max-width: 1000px) {
.shop main {
grid-template-columns: repeat(3, 1fr);
}
}
#media screen and (max-width: 700px) {
.shop main {
grid-template-columns: repeat(2, 1fr);
}
.shop .round {
position: static;
align-self: flex-end;
}
}
<section class="shop">
<header>
<h1>Welcome to the Shop</h1>
<p class="round">Round 1/10</p>
<p class="wallet iron-style">You have 1000 tokens</p>
</header>
<main>
<div class="product" id="product-1">
<div class="pic-layout">
<img src="https://picsum.photos/seed/prods1/150/100" />
</div>
<div class="price iron-style">5 Rubis</div>
</div>
<div class="product" id="product-2">
<div class="pic-layout">
<img src="https://picsum.photos/seed/prods2/150/100" />
</div>
<div class="price iron-style">25 Rubis</div>
</div>
<div class="product" id="product-3">
<div class="pic-layout">
<img src="https://picsum.photos/seed/prods3/150/100" />
</div>
<div class="price iron-style">15 Rubis</div>
</div>
<div class="product" id="product-4">
<div class="pic-layout">
<img src="https://picsum.photos/seed/prods4/150/100" />
</div>
<div class="price iron-style">42 Rubis</div>
</div>
<div class="product" id="product-5">
<div class="pic-layout">
<img src="https://picsum.photos/seed/prods5/150/100" />
</div>
<div class="price iron-style">120 Rubis</div>
</div>
<div class="product" id="product-6">
<div class="pic-layout">
<img src="https://picsum.photos/seed/prods6/150/100" />
</div>
<div class="price iron-style">33 Rubis</div>
</div>
<div class="product" id="product-7">
<div class="pic-layout">
<img src="https://picsum.photos/seed/prods7/150/100" />
</div>
<div class="price iron-style">6 Rubis</div>
</div>
<div class="product" id="product-8">
<div class="pic-layout">
<img src="https://picsum.photos/seed/prods8/150/100" />
</div>
<div class="price iron-style">44 Rubis</div>
</div>
<div class="product" id="product-9">
<div class="pic-layout">
<img src="https://picsum.photos/seed/prods9/150/100" />
</div>
<div class="price iron-style">99 Rubis</div>
</div>
<div class="product" id="product-10">
<div class="pic-layout">
<img src="https://picsum.photos/seed/prods10/150/100" />
</div>
<div class="price iron-style">1 Rubis</div>
</div>
<div class="product" id="product-11">
<div class="pic-layout">
<img src="https://picsum.photos/seed/prods11/150/100" />
</div>
<div class="price iron-style">23 Rubis</div>
</div>
<div class="product" id="product-12">
<div class="pic-layout">
<img src="https://picsum.photos/seed/prods12/150/100" />
</div>
<div class="price iron-style">16 Rubis</div>
</div>
</main>
</section>
This time I structured the shop with one wrapper div per product, but I could have avoided that using the same kind of grid as in my previous answer.
There are no vertical separators as CSS grid does not allow for inner borders (yet). If this is a requirement, the <main> element should be replaced with a <table>, which allows for all kinds of borders.
grid has the advantage of offering responsive layout using #media queries. That's why you can see all products on only 2 columns in the sample above, unless you enlarge it to full page.

Related

Element with position absolute and bottom: 0px; doesnt stich to the bottom

Im new to code,
I gave the image element(the bee), position: absolute and bottom: 0px, in order to make the element stick to the bottom of the body i.e. the bottom of the page. However, if I dont give the body position: relative, it doesnt work! Based on what I learnt, if there is no any parent that has position that is not static it automatically set itself in relation to the body, so it doesnt work in that case?
HTML
<body>
<img src="https://media.npr.org/assets/img/2018/06/07/gettyimages-200415242-001_slide-d26f3af782b697f15ceebe2f7c380c0e545dd47b.jpg" alt="" class="test-bee">
<div class="container">
<div class="main">
<div class="info">
<h1>10,000+ of our users love our products.</h1>
<p>We only provide great products combined with excellent customer service.
See what our satisfied customers are saying about our services.</p>
</div>
<div class="rates">
<div class="rate-container">
<div class="star-container">
<img src="./images/icon-star.svg" alt="">
<img src="./images/icon-star.svg" alt="">
<img src="./images/icon-star.svg" alt="">
<img src="./images/icon-star.svg" alt="">
<img src="./images/icon-star.svg" alt="">
</div>
<p class="review">Rated 5 Stars in Reviews</p>
</div>
<div class="rate-container">
<div class="star-container">
<img src="./images/icon-star.svg" alt="">
<img src="./images/icon-star.svg" alt="">
<img src="./images/icon-star.svg" alt="">
<img src="./images/icon-star.svg" alt="">
<img src="./images/icon-star.svg" alt="">
</div>
<p class="review">Rated 5 Stars in Report Guru</p>
</div>
<div class="rate-container">
<div class="star-container">
<img src="./images/icon-star.svg" alt="">
<img src="./images/icon-star.svg" alt="">
<img src="./images/icon-star.svg" alt="">
<img src="./images/icon-star.svg" alt="">
<img src="./images/icon-star.svg" alt="">
</div>
<p class="review">Rated 5 Stars in BestTech</p>
</div>
</div>
</div>
<section class="testemonies">
<div class="testemony-card">
<div class="user-info">
<div class="img-container">
<img src="./images/image-colton.jpg" alt="">
</div>
<div class="user-name-status">
<p class="user-name">colton smith </p>
<p class="status"><span>verified buyer</span></p>
</div>
</div>
<p class="testimony">"We needed the same printed design as the one we had ordered a week prior.
Not only did they find the original order, but we also received it in time.
Excellent!"</p>
</div>
<div class="testemony-card">
<div class="user-info">
<div class="img-container">
<img src="./images/image-irene.jpg" alt="">
</div>
<div class="user-name-status">
<p class="user-name">irene roberts </p>
<p class="status"><span>verified buyer</span></p>
</div>
</div>
<p class="testimony">
"Customer service is always excellent and very quick turn around. Completely
delighted with the simplicity of the purchase and the speed of delivery."</p>
</div>
<div class="testemony-card">
<div class="user-info">
<div class="img-container">
<img src="./images/image-anne.jpg" alt="">
</div>
<div class="user-name-status">
<p class="user-name">anne wallace </p>
<p class="status"><span>verified buyer</span></p>
</div>
</div>
<p class="testimony">
"Put an order with this company and can only praise them for the very high
standard. Will definitely use them again and recommend them to everyone!"</p>
</div>
</section>
</div>
</body>
CSS
* {
padding: 0px;
margin: 0px;
box-sizing: border-box;
}
:root {
--Very-Dark-Magenta: hsl(300, 43%, 22%);
--Soft-Pink: hsl(333, 80%, 67%);
--Dark-Grayish-Magenta: hsl(303, 10%, 53%);
--Light-Grayish-Magenta: hsl(300, 24%, 96%);
--White: hsl(0, 0%, 100%);
}
body {
width: 100%;
min-height: 100vh;
font-family: 'League Spartan', sans-serif;
font-size: 15px;
display: flex;
align-items: center;
justify-content: center;
/* border: 5px solid red; */
padding: 1em;
position: relative; /*why do i need this relative? the bottom image should stick to the bottom by default cause the body is the first one that had position relative, but without it it doesnt stick*/
}
.pattern {
display: none;
}
.test-bee {
width: 200px;
position: absolute;
bottom: 0px;
}
.bottom-mobile, .top-mobile {
display: block;
position: absolute;
}
.top-mobile {
top:0px;
}
.bottom-mobile {
bottom: 0px;
}
.container {
height: 100%;
/* border: 5px solid green; */
margin: 3em 0px;
}
.main {
text-align: center;
margin-bottom: 3em;
}
.info h1 {
margin: 0px auto;
line-height: 0.8em;
margin-bottom: 1em;
margin: 1em 2em;
color: var(--Very-Dark-Magenta)
}
.info {
line-height: 1.3em;
margin-bottom: 2.5em;
}
.rate-container {
background-color: var(--Light-Grayish-Magenta);
padding: 1em 2em;
margin-bottom: 1em;
border-radius: 0.4em;
display: flex;
flex-direction: column;
gap: 0.5em;
color: var(--Very-Dark-Magenta);
font-weight: bold;
}
.testemonies {
display: flex;
flex-direction: column;
gap: 1em;
}
.testemony-card {
background-color: var(--Very-Dark-Magenta);
border-radius: 0.4em;
color: white;
padding: 2em;
line-height: 1.2em;
}
.img-container {
width: 30px;
height: 30px;
border-radius: 50px;
overflow: hidden;
}
.img-container img {
height: 100%;
width: 100%;
}
.user-info {
display: flex;
align-items: center;
gap: 1em;
text-transform: capitalize;
margin-bottom: 1em;
}
.user-name-status p span{
color:var(--Soft-Pink)
}
I fix it by adding the body position: relative, but it should go like that

overflow scroll not adjusting height of div

My issue:
I'm making somewhat of a Zillow clone. I need the page to not expand beyond 100% of the viewport height however, I'm making a section with the intentions of having the overflow property set to scroll. When I do this, the section expands beyond the viewport height and leaves a large whitespace at the bottom of my page. I can adjust the height to fill up to 100vh however, if I adjust the screen vertically the div with the scroll overflow doesn't adjust to the viewport height. Thanks for any and all help!
Here's a screenshot of my issue:
The circled section is the section that I need the overflow to scroll:
This is my HTML for the entire 'popup' portion:
<div class="home__popup--backdrop">
<div class="home__popup--container">
<div class="home__popup--left">
<div class="home__popup--img--container">
<div class="home__popup--img--main--container">
<img src="./src/img/home-0.jpg" alt="home-0" class="home__popup--img--main">
</div>
<div class="home__popup--img--sub--container">
<img src="./src/img/home-1.jpg" alt="home-0" class="home__popup--img--sub">
<img src="./src/img/home-2.jpg" alt="home-0" class="home__popup--img--sub">
<img src="./src/img/home-3.jpg" alt="home-0" class="home__popup--img--sub">
<img src="./src/img/home-4.jpg" alt="home-0" class="home__popup--img--sub">
<img src="./src/img/home-5.jpg" alt="home-0" class="home__popup--img--sub">
<img src="./src/img/home-0.jpg" alt="home-0" class="home__popup--img--sub">
<img src="./src/img/home-1.jpg" alt="home-0" class="home__popup--img--sub">
<img src="./src/img/home-2.jpg" alt="home-0" class="home__popup--img--sub">
</div>
</div>
</div>
<div class="home__popup--right">
<div class="home__popup--header--container">
<div class="home__popup--logo--container">
<div class="logo__container--home">
<img src="./src/img/logo__house.svg" alt="logo-homes" class="logo logo__homes logo__homes--small">
</div>
<div class="logo__container--txt">
<img src="./src/img/logo__txt.svg" alt="logo-homes" class="logo logo__homes logo__txt--small">
</div>
</div>
<div class="home__popup--social--container">
<div class="home__popup--social">
<img src="./src/img/like.svg" alt="logo like" class="popup__logo logo__like">
<p>Save</p>
</div>
<div class="home__popup--share">
<div class="home__popup--social">
<img src="./src/img/next.svg" alt="logo next" class="popup__logo logo__next">
<p>Share</p>
</div>
</div>
<div class="home__popup--more">
<div class="home__popup--social">
<img src="./src/img/more.svg" alt="logo more" class="popup__logo logo__more">
<p>More</p>
</div>
</div>
</div>
</div>
<div class="home__popup--details--container">
<div class="home__popup--details">
<p class="home__popup--price">$500,000</p>
<p class="home__popup--beds home__popup--details--home">3 <span>bds</span></p>
<p class="home__popup--baths home__popup--details--home">2 <span>ba</span></p>
<p class="home__popup--sqft home__popup--details--home">2,245 <span>sqft</span></p>
</div>
<div class="home__popup--address--container">
<p class="home__popup--address">
4210 sharman rd<span>,&nbsp</span>
</p>
<p class="home__popup--city">Madison<span>,&nbsp</span></p>
<p class="home__popup--state">WI</p>
</div>
<div class="home__popup--btn--container">
<button class="btn__agent">Contact Agent</button>
</div>
</div>
<div class="home__popup--overview--container">
<div class="home__popup--overview--container--links">
<img src="./src/img/001-left-arrow.svg" alt="arrow-left" class = 'arrow-small arrow-small--left'>
<div class="home__popup--overview home__popup--overview--active home__popup--overview--container--links--text--container" data-list-section = 0>
<p class="home__popup--overview--text home__popup--overview--container--links--text">Overview</p>
</div>
<div class="home__popup--facts home__popup--overview--container--links--text--container">
<p class="home__popup--facts--text home__popup--overview--container--links--text">Facts and features</p>
</div>
<div class="home__popup--value home__popup--overview--container--links--text--container">
<p class="home__popup--value--text home__popup--overview--container--links--text">Home value</p>
</div>
<div class="home__popup--history home__popup--overview--container--links--text--container" data-list-section = 1>
<p class="home__popup--history--text home__popup--overview--container--links--text">Price and tax history</p>
</div>
<div class="home__popup--monthly home__popup--overview--container--links--text--container">
<p class="home__popup--monthly--text home__popup--overview--container--links--text">Monthly cost</p>
</div>
<div class="home__popup--rental home__popup--overview--container--links--text--container">
<p class="home__popup--rental--text home__popup--overview--container--links--text">Rental Value</p>
</div>
<div class="home__popup--schools home__popup--overview--container--links--text--container" data-list-section = 2>
<p class="home__popup--schools--text home__popup--overview--container--links--text">Nearby schools</p>
</div>
<div class="home__popup--similar home__popup--overview--container--links--text--container">
<p class="home__popup--similar--text home__popup--overview--container--links--text">Similar homes</p>
</div>
<div class="home__popup--neighborhood home__popup--overview--container--links--text--container">
<p class="home__popup--neighborhood--text home__popup--overview--container--links--text">Neighborhood</p>
</div>
<div class="home__popup--homes-for-you home__popup--overview--container--links--text--container">
<p class="home__popup--homes-for-you--text home__popup--overview--container--links--text">Homes for you</p>
</div>
<img src="./src/img/002-right-arrow.svg" alt="arrow-right" class = 'arrow-small arrow-small--right'>
</div>
<div class="home__popup--scroll">
<div class="home__popup--home--detail--container">
<div class="home__popup--map--container">
<div class="test" id = "home__popup--map"></div>
</div>
<div class="home__popup--text--container">
<div class="home__popup--text--stats">
<P class="home__popup--text--header">Overview</P>
<div class="home__popup--text--user-activity">
<p class="home__popup--text--time">Time on Home Finder &nbsp<span> --</span></p>
<p class="home__popup--text--views">Views <span>64</span></p>
<p class="home__popup--text--saves">Saves <span>1</span></p>
</div>
<p class="home__popup--text--description">
No showings until 8/22 OH.....
</p>
<p class="home__popup--text--read-more">Read more</p>
</div>
<p class="home__popup--text--open-house--header">Open House</p>
<p class="home__popup--text--open-house--day">Sun, Aug 22</p>
<p class="home__popup--text--open-house--time">12:00 PM - 2:00 PM</p>
<ul class="home__popup--text--agent--container">
<li class="home__popup--text--agent">Kavita Biyani</li>
<li class="home__popup--text--agent">Nik Tantardini</li>
<li class="home__popup--text--agent">First Weber INC</li>
<li class="home__popup--text--agent">Lena Oberwetter</li>
<li class="home__popup--text--agent">Prince Michael</li>
</ul>
<div class="home__popup--overview--text">
</div>
<div class="home--popup--overview--specs">
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
Here's the HTML for the overflowed portion:
<div class="home__popup--scroll">
<div class="home__popup--home--detail--container">
<div class="home__popup--map--container">
<div class="test" id = "home__popup--map"></div>
</div>
<div class="home__popup--text--container">
<div class="home__popup--text--stats">
<P class="home__popup--text--header">Overview</P>
<div class="home__popup--text--user-activity">
<p class="home__popup--text--time">Time on Home Finder &nbsp<span> --</span></p>
<p class="home__popup--text--views">Views <span>64</span></p>
<p class="home__popup--text--saves">Saves <span>1</span></p>
</div>
<p class="home__popup--text--description">
No showings until 8/22 OH. Amazing opportunity ...
</p>
<p class="home__popup--text--read-more">Read more</p>
</div>
<p class="home__popup--text--open-house--header">Open House</p>
<p class="home__popup--text--open-house--day">Sun, Aug 22</p>
<p class="home__popup--text--open-house--time">12:00 PM - 2:00 PM</p>
<ul class="home__popup--text--agent--container">
<li class="home__popup--text--agent">Kavita Biyani</li>
<li class="home__popup--text--agent">Nik Tantardini</li>
<li class="home__popup--text--agent">First Weber INC</li>
<li class="home__popup--text--agent">Lena Oberwetter</li>
<li class="home__popup--text--agent">Prince Michael</li>
</ul>
<div class="home__popup--overview--text">
</div>
<div class="home--popup--overview--specs">
</div>
</div>
</div>
Here is the relevant css:
.home__popup {
&--home--detail--container {
}
&--text {
&--description{
font-size: 1.8rem;
font-weight: 300;
color: $color-grey-text;
line-height: 1.3;
}
&--user-activity{
display: flex;
margin-bottom: 2rem;
font-size: 1.4rem;
color: $color-grey-text;
& span{
color: black;
}
}
&--time{
margin-right: 2rem;
border-right: 1px solid $color-grey-medium;
& span{
font-weight: bold;
margin-right: 2rem;
}
}
&--saves{
margin-left: 2rem;
& span{
font-weight: bold;
}
}
&--views{
margin-right: 2rem;
border-right: 1px solid $color-grey-medium;
& span{
font-weight: bold;
margin-right: 2rem;
}
}
&--header {
font-size: 2rem;
font-weight: 700;
letter-spacing: 0.5px;
margin-bottom: 2rem;
}
&--container {
margin-top: 2rem;
display: flex;
flex-direction: column;
margin-left: 1rem;
}
}
&--btn {
&--container {
margin-top: 1rem;
margin-left: 1rem;
display: flex;
justify-content: space-between;
width: 100%;
position: relative;
}
}
&--address {
&--container {
display: flex;
font-weight: 300;
font-size: 1.6rem;
margin-left: 1rem;
margin-top: 1rem;
}
}
&--baths {
margin-left: 0.5rem;
}
&--beds {
margin-left: 2rem;
}
&--price {
margin-top: 3rem;
font-size: 2.5rem;
font-weight: 500;
margin-left: 1rem;
}
&--social {
cursor: pointer;
&--container {
display: flex;
align-items: center;
width: 45%;
justify-content: space-around;
}
}
&--backdrop {
width: 100vw;
height: 100vh;
z-index: 2999;
position: absolute;
top: 0;
left: 0;
backdrop-filter: blur(2px);
background-color: rgba(0, 0, 0, 0.671);
}
&--container {
position: absolute;
top: 0;
left: 50%;
height: 100vh;
width: 65vw;
background-color: white;
transform: translateX(-50%);
z-index: 3000;
backdrop-filter: blur(2px);
display: flex;
flex-direction: row;
}
&--left {
position: relative;
width: 60%;
overflow-y: scroll;
}
&--right {
width: 40%;
position: relative;
}
&--img {
&--main {
height: auto;
object-fit: cover;
width: 100%;
}
&--sub {
height: 25rem;
object-fit: cover;
width: 49.5%;
margin-bottom: 0.4rem;
&--container {
display: flex;
flex-wrap: wrap;
justify-content: space-between;
align-items: center;
}
}
}
&--header {
&--container {
display: flex;
justify-content: space-between;
position: relative;
border-bottom: 1px solid #6060607a;
margin-left: 1rem;
margin-right: 1rem;
}
}
&--logo {
&--container {
display: flex;
transform: translateY(1rem);
}
&__homes {
&--small {
height: 6rem;
width: 7rem;
}
}
}
&--details {
display: flex;
align-items: flex-end;
&--container {
display: flex;
flex-direction: column;
position: relative;
}
&--home {
font-size: 1.6rem;
font-weight: 400;
& span {
border-right: 1px solid $color-grey-text;
padding-right: 0.5rem;
font-weight: 300;
}
}
}
&--sqft {
margin-left: 0.5rem;
& span {
border-right: none;
}
}
&--overview {
color: $color-primary;
border-bottom: 2px solid $color-primary;
&--container {
display: flex;
flex-direction: column;
position: relative;
&--links {
display: flex;
overflow-x: scroll;
font-size: 14px;
font-weight: 300;
height: 5rem;
align-items: center;
margin-top: 2rem;
border-top: 1px solid $color-grey-medium;
border-bottom: 1px solid $color-grey-medium;
margin-left: 0.5rem;
margin-right: 0.5rem;
&::-webkit-scrollbar {
display: none;
}
&--text {
margin-left: 1rem;
margin-right: 1rem;
width: max-content;
&--container {
cursor: pointer;
height: 100%;
display: flex;
align-items: center;
transition: .2s all;
&:hover {
color: $color-primary-light;
}
}
}
}
}
}
}
I was having way too many issues out of pure stubbornness of not wanting to change my css however, I finally gave in and refactored the section as a grid. I'm now able to get it to function properly. Here's what it looks like:
And here's the css for the grid-layout:
&--right {
width: 40%;
position: relative;
display: grid;
grid-template-columns: repeat(2, 1fr);
grid-template-rows: 5rem 20rem 5rem auto;
}
here's the CSS for the updated div containing the scroll bar:
&--scroll{
grid-column: 1/-1;
grid-row: 4/5;
overflow-y: scroll;
overflow-x: hidden;
}

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>

Html: Video card img a hover

hello I want to have a "how" when I go over the picture but the heart is positioned elsewhere. where is the mistake?
and the point I don't understand is why does my card width seem to be overflowing?
Because of the overflow I showed in the picture. When I add a card to the 2nd card. The cards are coming upside down.
.card-video {
width: 305px;
display: flex;
flex-direction: column;
}
.card-pic img {
object-fit: cover;
width: 100%;
height: 100%;
max-width: 305px;
max-height: 170px;
}
.card-info-logo {
position: absolute;
right: 5px;
top: -28px;
}
.card-info-logo img {
width: 55px;
border-radius: 50%;
border: 4px solid #5e4b55;
}
.card-info {
position: relative;
background-color: #292828;
height: 90px;
padding: 7px 10px 10px 10px;
display: flex;
flex-direction: column;
}
.card-info-top {
flex: 1;
display: flex;
flex-direction: column;
justify-content: space-between;
}
.card-info .card-info-category {
color: #546e7a;
font-size: 14px;
}
.card-info .card-info-title {
color: #546e7a;
font-size: 14px;
padding-bottom: 5px;
}
.card-info-bottom {
border-top: solid 1px #44393e;
padding-top: 7px;
display: flex;
align-items: center;
line-height: 1;
justify-content: space-between;
}
.card-info .card-info-bottom .views {
color: #546e7a;
font-size: 12px;
}
.card-info .card-info-bottom .date {
color: #546e7a;
font-size: 12px;
}
.card-pic {
display: flex;
flex-wrap: wrap;
margin: 0;
padding: 0;
list-style: none;
}
.clip-icon {
position: relative;
}
.clip-icon:hover {
background-color: red;
}
<div class="card-video">
<div class="card-pic">
<a href="">
<img src="https://i.ytimg.com/vi/VeDmG7YovSM/maxresdefault.jpg" alt="">
<div class="clip-icon">
<span class="fa fa-heart"></span>
</div>
</a>
</div>
<div class="card-info mt-1">
<div class="card-info-logo">
<img src="https://yt3.ggpht.com/a/AATXAJxBc7gQx7gKOeJG0uTgpfZVUA1FT_EOxjVjYtI-=s100-c-k-c0xffffffff-no-rj-mo" alt="">
</div>
<div class="card-info-top">
<div class="card-info-category">Video Category</div>
<div class="card-info-title">Video Title</div>
</div>
<div class="card-info-bottom">
<div class="views">312K</div>
<div class="date">16 hour ago</div>
</div>
</div>
</div>
.card-video is having flow direction column.
If you try to put the more card like this it will always show in upside down like a stack. Wrap the entire thing in div and provide the flow-direction: row and flex-wrap : wrap to get desired result.
<style>
.box{
display:flex;
flex-direction:row;
flex-wrap:wrap;
}
.card-video {
width: 305px;
display: flex;
flex-direction: column;
margin:0.5rem;
}
.card-pic img {
object-fit: cover;
width: 100%;
height: 100%;
max-width: 305px;
max-height: 170px;
}
.card-info-logo {
position: absolute;
right: 5px;
top: -28px;
}
.card-info-logo img {
width: 55px;
border-radius: 50%;
border: 4px solid #5e4b55;
}
.card-info {
position: relative;
background-color: #292828;
height: 90px;
padding: 7px 10px 10px 10px;
display: flex;
flex-direction: column;
}
.card-info-top {
flex: 1;
display: flex;
flex-direction: column;
justify-content: space-between;
}
.card-info .card-info-category {
color: #546e7a;
font-size: 14px;
}
.card-info .card-info-title {
color: #546e7a;
font-size: 14px;
padding-bottom: 5px;
}
.card-info-bottom {
border-top: solid 1px #44393e;
padding-top: 7px;
display: flex;
align-items: center;
line-height: 1;
justify-content: space-between;
}
.card-info .card-info-bottom .views {
color: #546e7a;
font-size: 12px;
}
.card-info .card-info-bottom .date {
color: #546e7a;
font-size: 12px;
}
.card-pic {
display: flex;
flex-wrap: wrap;
margin: 0;
padding: 0;
list-style: none;
}
.clip-icon {
position: relative;
}
.clip-icon:hover {
background-color: red;
}
</style>
<div class="box">
<div class="card-video">
<div class="card-pic">
<a href="">
<img src="https://i.ytimg.com/vi/VeDmG7YovSM/maxresdefault.jpg" alt="">
<div class="clip-icon">
<span class="fa fa-heart"></span>
</div>
</a>
</div>
<div class="card-info mt-1">
<div class="card-info-logo">
<img src="https://yt3.ggpht.com/a/AATXAJxBc7gQx7gKOeJG0uTgpfZVUA1FT_EOxjVjYtI-=s100-c-k-c0xffffffff-no-rj-mo" alt="">
</div>
<div class="card-info-top">
<div class="card-info-category">Video Category</div>
<div class="card-info-title">Video Title</div>
</div>
<div class="card-info-bottom">
<div class="views">312K</div>
<div class="date">16 hour ago</div>
</div>
</div>
</div>
<div class="card-video">
<div class="card-pic">
<a href="">
<img src="https://i.ytimg.com/vi/VeDmG7YovSM/maxresdefault.jpg" alt="">
<div class="clip-icon">
<span class="fa fa-heart"></span>
</div>
</a>
</div>
<div class="card-info mt-1">
<div class="card-info-logo">
<img src="https://yt3.ggpht.com/a/AATXAJxBc7gQx7gKOeJG0uTgpfZVUA1FT_EOxjVjYtI-=s100-c-k-c0xffffffff-no-rj-mo" alt="">
</div>
<div class="card-info-top">
<div class="card-info-category">Video Category</div>
<div class="card-info-title">Video Title</div>
</div>
<div class="card-info-bottom">
<div class="views">312K</div>
<div class="date">16 hour ago</div>
</div>
</div>
</div>
</box>
The flex-direction needs to be set to row, with flex-wrap:wrap as to format correctly.
The .clip-icon can be set to position:absolute if the parent element has position:relative applied.
You can set the clip-icon to display:none and get it to display on picture hover by adding .card-pic:hover .clip-icon: { display:block; }
I have added a snippet below
.box{
display:flex;
flex-direction:row;
flex-wrap:wrap;
}
.card-video {
width: 305px;
display: flex;
flex-direction: column;
margin:0.5rem;
}
.card-pic img {
object-fit: cover;
width: 100%;
height: 100%;
max-width: 305px;
max-height: 170px;
}
.card-info-logo {
position: absolute;
right: 5px;
top: -28px;
}
.card-info-logo img {
width: 55px;
border-radius: 50%;
border: 4px solid #5e4b55;
}
.card-info {
position: relative;
background-color: #292828;
height: 90px;
padding: 7px 10px 10px 10px;
display: flex;
flex-direction: column;
}
.card-info-top {
flex: 1;
display: flex;
flex-direction: column;
justify-content: space-between;
}
.card-info .card-info-category {
color: #546e7a;
font-size: 14px;
}
.card-info .card-info-title {
color: #546e7a;
font-size: 14px;
padding-bottom: 5px;
}
.card-info-bottom {
border-top: solid 1px #44393e;
padding-top: 7px;
display: flex;
align-items: center;
line-height: 1;
justify-content: space-between;
}
.card-info .card-info-bottom .views {
color: #546e7a;
font-size: 12px;
}
.card-info .card-info-bottom .date {
color: #546e7a;
font-size: 12px;
}
.card-pic:hover .clip-icon{
display:block;
}
.card-pic {
display: flex;
flex-wrap: wrap;
margin: 0;
padding: 0;
list-style: none;
position:relative;
}
.clip-icon a {
position: relative
}
.clip-icon {
position: absolute;
bottom:10px;
left:5px;
width:20px;
height:20px;
background-color:white;
display:none;
}
.clip-icon:hover {
background-color: red;
}
<div class="box">
<div class="card-video">
<div class="card-pic">
<a href="">
<img src="https://i.ytimg.com/vi/VeDmG7YovSM/maxresdefault.jpg" alt="">
<div class="clip-icon">
<span class="fa fa-heart"></span>
</div>
</a>
</div>
<div class="card-info mt-1">
<div class="card-info-logo">
<img src="https://yt3.ggpht.com/a/AATXAJxBc7gQx7gKOeJG0uTgpfZVUA1FT_EOxjVjYtI-=s100-c-k-c0xffffffff-no-rj-mo" alt="">
</div>
<div class="card-info-top">
<div class="card-info-category">Video Category</div>
<div class="card-info-title">Video Title</div>
</div>
<div class="card-info-bottom">
<div class="views">312K</div>
<div class="date">16 hour ago</div>
</div>
</div>
</div>
<div class="card-video">
<div class="card-pic">
<a href="">
<img src="https://i.ytimg.com/vi/VeDmG7YovSM/maxresdefault.jpg" alt="">
<div class="clip-icon">
<span class="fa fa-heart"></span>
</div>
</a>
</div>
<div class="card-info mt-1">
<div class="card-info-logo">
<img src="https://yt3.ggpht.com/a/AATXAJxBc7gQx7gKOeJG0uTgpfZVUA1FT_EOxjVjYtI-=s100-c-k-c0xffffffff-no-rj-mo" alt="">
</div>
<div class="card-info-top">
<div class="card-info-category">Video Category</div>
<div class="card-info-title">Video Title</div>
</div>
<div class="card-info-bottom">
<div class="views">312K</div>
<div class="date">16 hour ago</div>
</div>
</div>
</div>
</box>

how to put the text below the images without {css}

Whenever I'm trying to change .tea to display: block; all the images change their position from being horizontal, to being vertical
How to position it the correct way so the images keep being horizontally aligned and the text will be underneath
.tea {
display: inline-flex;
margin-left: 225px;
padding: 20px;
justify-content: center;
}
.tea h4 {
display: inline-block;
position: relative;
text-align: center;
}
.tea2 {
display: inline-flex;
margin-left: 385px;
}
.tea img {
width: 300px;
height: 200px;
padding: 25px;
border-radius: 15px;
}
.tea2 img {
width: 300px;
height: 200px;
padding: 30px;
}
<div class="tea">
<img class="1" src="https://via.placeholder.com/150">
<h4>Myrtle Ave</h4>
<img class="2" src="https://via.placeholder.com/150">
<h4>Spiced rum</h4>
<img class="3" src="https://via.placeholder.com/150">
<h4>Berry Blitz</h4>
</div>
<div class="tea2">
<img class="1" src="https://via.placeholder.com/150">
<img class="2" src="https://via.placeholder.com/150">
</div>
You should do it like this
* {
box-sizing: border-box;
}
html, body {
width: 100%;
height: 100%;
margin: 0;
}
#gallery {
display: flex;
flex-wrap: wrap;
}
#gallery .image-container {
width: 25%;
background-color: lightgreen;
border-radius: 5px;
padding: 5px;
box-shadow: 1px 1px 2px #000, -1px -1px 2px #000;
}
#gallery img {
width: 100%;
}
#gallery .title {
font: bold 24px monospace;
text-align: center;
color: white;
margin: 2%;
}
<div id="gallery">
<div class="image-container">
<img src="https://openclipart.org/image/800px/svg_to_png/321159/hotwork-sign-arvin61r58.png">
<p class="title">Image 1</p>
</div>
<div class="image-container">
<img src="https://openclipart.org/image/800px/svg_to_png/321159/hotwork-sign-arvin61r58.png">
<p class="title">Image 2</p>
</div>
<div class="image-container">
<img src="https://openclipart.org/image/800px/svg_to_png/321159/hotwork-sign-arvin61r58.png">
<p class="title">Image 3</p>
</div>
<div class="image-container">
<img src="https://openclipart.org/image/800px/svg_to_png/321159/hotwork-sign-arvin61r58.png">
<p class="title">Image 4</p>
</div>
<div class="image-container">
<img src="https://openclipart.org/image/800px/svg_to_png/321159/hotwork-sign-arvin61r58.png">
<p class="title">Image 5</p>
</div>
<div class="image-container">
<img src="https://openclipart.org/image/800px/svg_to_png/321159/hotwork-sign-arvin61r58.png">
<p class="title">Image 6</p>
</div>
<div class="image-container">
<img src="https://openclipart.org/image/800px/svg_to_png/321159/hotwork-sign-arvin61r58.png">
<p class="title">Image 7</p>
</div>
<div class="image-container">
<img src="https://openclipart.org/image/800px/svg_to_png/321159/hotwork-sign-arvin61r58.png">
<p class="title">Image 8</p>
</div>
</div>
You need to change you HTML to support what you want. Use a container wrapper around the image and image text.
Example: https://jsfiddle.net/Lqupmf5s/
<div class="tea">
<div class="img-container">
<img class="1" src="32131">
<h4>Myrtle Ave</h4>
</div>
<div class="img-container">
<img class="2" src="3213">
<h4>Spiced rum</h4>
</div>
<div class="img-container">
<img class="3" src="3213">
<h4>Berry Blitz</h4>
</div>
</div>
.tea {
display: inline-flex;
/* margin-left: 225px; */
padding: 20px;
justify-content: center; }
.tea h4{
display: inline-block;
position: relative;
text-align: center; }
.tea2 {
display: inline-flex;
margin-left: 385px; }
.tea img {
width: 300px;
height: 200px;
/* padding: 25px; */
border-radius: 15px; }
.tea2 img {
width: 300px;
height: 200px;
padding: 30px; }