I'm learning CSS and I have a problem with CSS flexbox and grid.
I wanted to make a grid as shown above but I couldn't. The first and last containers are in different sizes and the others are the same.
Here is my code:
.second-section {
width: 80%;
margin: 10px auto;
display: flex;
flex-direction: row;
position: relative;
flex-wrap: wrap;
}
.category-devider {
width: 80%;
margin: 0 auto;
}
.category-devider p {
font-size: 16px;
}
.category-devider span {
font-size: 18px;
color: #757575;
}
.image-containers {
position: relative;
width: 45%;
margin: 50px auto;
height: 434px;
background-color: #494949;
display: block;
text-align: center;
}
.image-containers h3 {
font-size: 18px;
}
.second-section #img-container img {
height: 100%;
width: 100%;
object-fit: cover;
}
.img1 img {
height: 612px;
}
<div class="second-section">
<div class="image-containers img1">
<img src="/img/apple-watch.jpg" alt="Apple Watch" />
<h3>Rule ratio</h3>
<p>Product design</p>
</div>
<div class="image-containers img2">
<img src="/img/circle.jpg" alt="Situation" />
<h3>Situation</h3>
<p>Visual identity</p>
</div>
<div class="image-containers img3">
<img src="/img/cards.jpg" alt="Cards" />
<h3>Dry air</h3>
<p>User research</p>
</div>
<div class="image-containers img4">
<img src="/img/orange-phone.jpeg" alt="Phone" />
<h3>Vertical</h3>
<p>Product design</p>
</div>
<div class="image-containers img5">
<img src="/img/phone.jpg" alt="Phone" />
<h3>Variable compose</h3>
<p>Product design</p>
</div>
<div class="image-containers img6">
<img src="/img/phone1.jpg" alt="Phone" />
<h3>Scope shift</h3>
<p>Product design</p>
</div>
</div>
You can make array of objects:
{
name: 'name',
title: 'title',
text: 'text'
}
and write:
<div class="second-section">
{array.map((picture, index) => {
<div class={`image-containers img${index}`}>
<img src={`/img/${name}.jpg`} alt="Phone" />
<h3>{picture.title}</h3>
<p>{picture.text}</p>
</div>
})}
</div>
I created this product card slider but it's prev and nex buttons are not working. Also I tried some other ways but it affect my product card structure. So please, If there is any easy way to do this which does not affect my card structure it will be helpfull.
.container{
padding:80px 7%;
position: relative;
font-family: 'Open Sans', sans-serif;
}
.details{
display: flex;
justify-content: space-between;
margin: 20px 0px 30px 0px;
color: white;
}
.right{
max-width: 50%;
}
.container .box-container .box{
box-shadow: 0 5px 10px rgba(0,0,0,.3);
background:#0d1b2a;
padding:15px;
margin: 40px 0;
display: flex;
align-items: center;
flex-wrap: wrap;
gap:15px;
}
.container .box-container .box .image-container{
flex:1 1 500px;
display: flex;
align-items: center;
gap:15px;
}
.container .box-container .box .content{
flex:1 1 350px;
}
.container .box-container .box .image-container .small-image{
width:20%;
}
.container .box-container .box .image-container .big-image{
width:80%;
}
.container .box-container .box .image-container .small-image img{
width:100%;
padding:10px;
border:1px solid rgba(255, 255, 255, 0.3);
cursor: pointer;
}
.container .box-container .box .image-container .small-image img:hover{
background:rgba(167, 167, 167, 0.2);
}
.container .box-container .box .image-container .big-image img{
width:95%;
padding:20px;
filter: drop-shadow(0 5px 10px rgba(0,0,0,.2));
}
.container .box-container .box .content h3{
color:rgb(255, 255, 255);
font-size: 25px;
}
.hide-1{
background-color: transparent;
padding: 5px 10px;
border: 1px solid rgb(255, 255, 255);
color: rgb(255, 255, 255);
}
.product{
height: 100vh;
}
#media only screen and (max-width: 370px) {
.details{
flex-direction: column ;
}
.hide-1{
font-size: .8em;
}
}
/* --------------------------------------- */
html,
body {
height: 100%;
margin: 0px;
}
.slider {
width: 100%;
border-radius: 20px;
overflow: hidden;
}
.slides {
display: flex;
overflow-x: scroll;
position: relative;
scroll-behavior: smooth;
scroll-snap-type: x mandatory;
}
.slide:nth-of-type(even) {
background-color: rgb(250, 246, 212);
}
.slide {
display: flex;
justify-content: center;
align-items: center;
flex-shrink: 0;
width: 100%;
height: 400px;
scroll-snap-align: center;
margin-right: 0px;
box-sizing: border-box;
background: white;
transform-origin: center center;
transform: scale(1);
}
.slide__text {
font-size: 40px;
font-weight: bold;
font-family: sans-serif;
}
.slide a {
background: none;
border: none;
}
a.slide__prev,
.slider::before {
transform: rotate(135deg);
-webkit-transform: rotate(135deg);
left: 2%;
}
a.slide__next,
.slider::after {
transform: rotate(-45deg);
-webkit-transform: rotate(-45deg);
right: 2%;
}
.slider::before,
.slider::after,
.slide__prev,
.slide__next {
position: absolute;
top: 48%;
width: 35px;
height: 35px;
border: solid black;
border-width: 0 4px 4px 0;
padding: 3px;
box-sizing: border-box;
}
.slider::before,
.slider::after {
content: "";
z-index: 1;
background: none;
pointer-events: none;
}
.slider__nav {
box-sizing: border-box;
position: absolute;
bottom: 5%;
left: 50%;
width: 200px;
margin-left: -100px;
text-align: center;
}
.slider__navlink {
display: inline-block;
height: 15px;
width: 15px;
border-radius: 50%;
background-color: black;
margin: 0 10px 0 10px;
}
.read-article{
position: absolute;
top: 10px;
left: 10px;
z-index: 999;
color: #000;
background: white;
padding: 10px 20px;
border-radius: 10px;
font-family: arial;
text-decoration: none;
box-shadow: rgb(50 50 93 / 25%) 0 0 100px -20px, rgb(0 0 0 / 30%) 0 0 60px -15px;
}
.read-article:hover{
background: #d5d5d5;
box-shadow: rgb(50 50 93 / 25%) 0 0 100px -20px, rgb(0 0 0 / 30%) 0 0 60px 0px;
}
iframe[sandbox] .read-article{
display: none;
}
<div class="container slider-container">
<div class="box-container slider">
<div class="slides">
<div class="box slide" id="slides__1">
<div class="image-container">
<div class="small-image">
<img src="images/image_11.png" class="small-img-1" alt="">
<img src="images/image_12.png" class="small-img-1" alt="">
<img src="images/image_13.png" class="small-img-1" alt="">
<img src="images/image_14.png" class="small-img-1" alt="">
</div>
<div class="big-image">
<img src="images/image_11.png" class="big-img-1" alt="">
</div>
</div>
<div class="content">
<h3>Phillips</h3>
<div class="details">
<div class="left">
<p>ID: Mp2223-0</p>
<p>Modality: CT</p>
<p>Model: Ingenuity</p>
<p>YOM: 2016</p>
</div>
<div class="right">
<p>Slice: 128</p>
<p>Origin: UAE</p>
<p>Remark: System In Good Working Condition</p>
</div>
</div>
To Know more Call #8766474892
</div>
<a class="slide__prev" href="#slides__4" title="Prev"></a>
<a class="slide__next" href="#slides__2" title="Next"></a>
</div>
<div class="box slide" id="slides__2">
<div class="image-container">
<div class="small-image">
<img src="images/image_11.png" class="small-img-2" alt="">
<img src="images/image_12.png" class="small-img-2" alt="">
<img src="images/image_13.png" class="small-img-2" alt="">
<img src="images/image_14.png" class="small-img-2" alt="">
</div>
<div class="big-image">
<img src="images/image_11.png" class="big-img-2" alt="">
</div>
</div>
<div class="content">
<h3>Phillips</h3>
<div class="details">
<div class="left">
<p>ID: Mp2223-0</p>
<p>Modality: CT</p>
<p>Model: Ingenuity</p>
<p>YOM: 2016</p>
</div>
<div class="right">
<p>Slice: 128</p>
<p>Origin: UAE</p>
<p>Remark: System In Good Working Condition</p>
</div>
</div>
To Know more Call #8766474892
</div>
<a class="slide__prev" href="#slides__1" title="Prev"></a>
<a class="slide__next" href="#slides__3" title="Next"></a>
</div>
<div class="box slide" id="slides__3">
<div class="image-container">
<div class="small-image">
<img src="images/image_11.png" class="small-img-3" alt="">
<img src="images/image_12.png" class="small-img-3" alt="">
<img src="images/image_13.png" class="small-img-3" alt="">
<img src="images/image_14.png" class="small-img-3" alt="">
</div>
<div class="big-image">
<img src="images/image_11.png" class="big-img-3" alt="">
</div>
</div>
<div class="content">
<h3>Phillips</h3>
<div class="details">
<div class="left">
<p>ID: Mp2223-0</p>
<p>Modality: CT</p>
<p>Model: Ingenuity</p>
<p>YOM: 2016</p>
</div>
<div class="right">
<p>Slice: 128</p>
<p>Origin: UAE</p>
<p>Remark: System In Good Working Condition</p>
</div>
</div>
To Know more Call #8766474892
</div>
<a class="slide__prev" href="#slides__2" title="Prev"></a>
<a class="slide__next" href="#slides__4" title="Next"></a>
</div>
<div class="box slide" id="slides__4">
<div class="image-container">
<div class="small-image">
<img src="images/image_21.png" class="small-img-4" alt="">
<img src="images/image_22.png" class="small-img-4" alt="">
<img src="images/image_23.png" class="small-img-4" alt="">
<img src="images/image_24.png" class="small-img-4" alt="">
</div>
<div class="big-image">
<img src="images/image_11.png" class="big-img-4" alt="">
</div>
</div>
<div class="content">
<h3>Phillips</h3>
<div class="details">
<div class="left">
<p>ID: Mp2223-0</p>
<p>Modality: CT</p>
<p>Model: Ingenuity</p>
<p>YOM: 2016</p>
</div>
<div class="right">
<p>Slice: 128</p>
<p>Origin: UAE</p>
<p>Remark: System In Good Working Condition</p>
</div>
</div>
To Know more Call #8766474892
</div>
<a class="slide__prev" href="#slides__3" title="Prev"></a>
<a class="slide__next" href="#slides__1" title="Next"></a>
</div>
</div>
<div class="slider__nav">
<a class="slider__navlink" href="#slides__1"></a>
<a class="slider__navlink" href="#slides__2"></a>
<a class="slider__navlink" href="#slides__3"></a>
<a class="slider__navlink" href="#slides__4"></a>
</div>
</div>
</div>
Also I want to optimize my code so if it is possible let me know.
Thanks in advance.
You can use scrollIntoView() and based on the index of the slide which is currently in view ,the next and previous button will respond correctly.
Check the snippet below
var next=document.getElementsByClassName('slide__next')[0];
var prev=document.getElementsByClassName('slide__prev')[0];
var length= document.getElementsByClassName('slide').length;
var width_slide=document.getElementsByClassName('slides')[0].clientWidth;
var i=0,j=1;
var active=document.getElementsByClassName('active')[0];
var slide=Array.from(document.getElementsByClassName('slide'));
document.getElementsByClassName('slide')[0].classList.add('active');
next.addEventListener('click',function(){
let index=Array.from(document.getElementsByClassName('slide')).indexOf(document.getElementsByClassName('active')[0]);
if(index<(length-1))
{
document.getElementsByClassName('slide')[index].classList.remove('active');
document.getElementsByClassName('slide')[index+1].classList.add('active');
}
document.getElementsByClassName('active')[0].scrollIntoView();
})
prev.addEventListener('click',function(){
let index=Array.from(document.getElementsByClassName('slide')).indexOf(document.getElementsByClassName('active')[0]);
if(index>0)
{
document.getElementsByClassName('slide')[index].classList.remove('active');
document.getElementsByClassName('slide')[index-1].classList.add('active');
}
document.getElementsByClassName('active')[0].scrollIntoView();
})
.container{
padding:80px 7%;
position: relative;
font-family: 'Open Sans', sans-serif;
}
.details{
display: flex;
justify-content: space-between;
margin: 20px 0px 30px 0px;
color: white;
}
.right{
max-width: 50%;
}
.container .box-container .box{
box-shadow: 0 5px 10px rgba(0,0,0,.3);
background:#0d1b2a;
padding:15px;
margin: 40px 0;
display: flex;
align-items: center;
flex-wrap: wrap;
gap:15px;
}
.container .box-container .box .image-container{
flex:1 1 500px;
display: flex;
align-items: center;
gap:15px;
}
.container .box-container .box .content{
flex:1 1 350px;
}
.container .box-container .box .image-container .small-image{
width:20%;
}
.container .box-container .box .image-container .big-image{
width:80%;
}
.container .box-container .box .image-container .small-image img{
width:100%;
padding:10px;
border:1px solid rgba(255, 255, 255, 0.3);
cursor: pointer;
}
.container .box-container .box .image-container .small-image img:hover{
background:rgba(167, 167, 167, 0.2);
}
.container .box-container .box .image-container .big-image img{
width:95%;
padding:20px;
filter: drop-shadow(0 5px 10px rgba(0,0,0,.2));
}
.container .box-container .box .content h3{
color:rgb(255, 255, 255);
font-size: 25px;
}
.hide-1{
background-color: transparent;
padding: 5px 10px;
border: 1px solid rgb(255, 255, 255);
color: rgb(255, 255, 255);
}
.product{
height: 100vh;
}
#media only screen and (max-width: 370px) {
.details{
flex-direction: column ;
}
.hide-1{
font-size: .8em;
}
}
/* --------------------------------------- */
html,
body {
height: 100%;
margin: 0px;
}
.slider {
width: 100%;
border-radius: 20px;
overflow: hidden;
}
.slides {
display: flex;
overflow-x: scroll;
position: relative;
scroll-behavior: smooth;
scroll-snap-type: x mandatory;
}
.slide:nth-of-type(even) {
background-color: rgb(250, 246, 212);
}
.slide {
display: flex;
justify-content: center;
align-items: center;
flex-shrink: 0;
width: 100%;
height: 400px;
scroll-snap-align: center;
margin-right: 0px;
box-sizing: border-box;
background: white;
transform-origin: center center;
transform: scale(1);
}
.slide__text {
font-size: 40px;
font-weight: bold;
font-family: sans-serif;
}
.slide a {
background: none;
border: none;
}
a.slide__prev,
.slider::before {
transform: rotate(135deg);
-webkit-transform: rotate(135deg);
left: 2%;
}
a.slide__next,
.slider::after {
transform: rotate(-45deg);
-webkit-transform: rotate(-45deg);
right: 2%;
}
.slider::before,
.slider::after,
.slide__prev,
.slide__next {
position: absolute;
top: 48%;
width: 35px;
height: 35px;
border: solid black;
border-width: 0 4px 4px 0;
padding: 3px;
box-sizing: border-box;
}
.slider::before,
.slider::after {
content: "";
z-index: 1;
background: none;
pointer-events: none;
}
.slider__nav {
box-sizing: border-box;
position: absolute;
bottom: 5%;
left: 50%;
width: 200px;
margin-left: -100px;
text-align: center;
}
.slider__navlink {
display: inline-block;
height: 15px;
width: 15px;
border-radius: 50%;
background-color: black;
margin: 0 10px 0 10px;
}
.read-article{
position: absolute;
top: 10px;
left: 10px;
z-index: 999;
color: #000;
background: white;
padding: 10px 20px;
border-radius: 10px;
font-family: arial;
text-decoration: none;
box-shadow: rgb(50 50 93 / 25%) 0 0 100px -20px, rgb(0 0 0 / 30%) 0 0 60px -15px;
}
.read-article:hover{
background: #d5d5d5;
box-shadow: rgb(50 50 93 / 25%) 0 0 100px -20px, rgb(0 0 0 / 30%) 0 0 60px 0px;
}
iframe[sandbox] .read-article{
display: none;
}
<div class="container slider-container">
<div class="box-container slider">
<a class="slide__prev" href="#/" title="Prev"></a>
<a class="slide__next" href="#/" title="Next"></a>
<div class="slides check">
<div class="box slide" id="slides__1">
<div class="image-container">
<div class="small-image">
<img src="images/image_11.png" class="small-img-1" alt="">
<img src="images/image_12.png" class="small-img-1" alt="">
<img src="images/image_13.png" class="small-img-1" alt="">
<img src="images/image_14.png" class="small-img-1" alt="">
</div>
<div class="big-image">
<img src="images/image_11.png" class="big-img-1" alt="">
</div>
</div>
<div class="content">
<h3>Phillips</h3>
<div class="details">
<div class="left">
<p>ID: Mp2223-0</p>
<p>Modality: CT</p>
<p>Model: Ingenuity</p>
<p>YOM: 2016</p>
</div>
<div class="right">
<p>Slice: 128</p>
<p>Origin: UAE</p>
<p>Remark: System In Good Working Condition</p>
</div>
</div>
To Know more Call #8766474892
</div>
</div>
<div class="box slide" id="slides__2">
<div class="image-container">
<div class="small-image">
<img src="images/image_11.png" class="small-img-2" alt="">
<img src="images/image_12.png" class="small-img-2" alt="">
<img src="images/image_13.png" class="small-img-2" alt="">
<img src="images/image_14.png" class="small-img-2" alt="">
</div>
<div class="big-image">
<img src="images/image_11.png" class="big-img-2" alt="">
</div>
</div>
<div class="content">
<h3>Phillips</h3>
<div class="details">
<div class="left">
<p>ID: Mp2223-0</p>
<p>Modality: CT</p>
<p>Model: Ingenuity</p>
<p>YOM: 2016</p>
</div>
<div class="right">
<p>Slice: 128</p>
<p>Origin: UAE</p>
<p>Remark: System In Good Working Condition</p>
</div>
</div>
To Know more Call #8766474892
</div>
</div>
<div class="box slide" id="slides__3">
<div class="image-container">
<div class="small-image">
<img src="images/image_11.png" class="small-img-3" alt="">
<img src="images/image_12.png" class="small-img-3" alt="">
<img src="images/image_13.png" class="small-img-3" alt="">
<img src="images/image_14.png" class="small-img-3" alt="">
</div>
<div class="big-image">
<img src="images/image_11.png" class="big-img-3" alt="">
</div>
</div>
<div class="content">
<h3>Phillips</h3>
<div class="details">
<div class="left">
<p>ID: Mp2223-0</p>
<p>Modality: CT</p>
<p>Model: Ingenuity</p>
<p>YOM: 2016</p>
</div>
<div class="right">
<p>Slice: 128</p>
<p>Origin: UAE</p>
<p>Remark: System In Good Working Condition</p>
</div>
</div>
To Know more Call #8766474892
</div>
</div>
<div class="box slide" id="slides__4">
<div class="image-container">
<div class="small-image">
<img src="images/image_21.png" class="small-img-4" alt="">
<img src="images/image_22.png" class="small-img-4" alt="">
<img src="images/image_23.png" class="small-img-4" alt="">
<img src="images/image_24.png" class="small-img-4" alt="">
</div>
<div class="big-image">
<img src="images/image_11.png" class="big-img-4" alt="">
</div>
</div>
<div class="content">
<h3>Phillips</h3>
<div class="details">
<div class="left">
<p>ID: Mp2223-0</p>
<p>Modality: CT</p>
<p>Model: Ingenuity</p>
<p>YOM: 2016</p>
</div>
<div class="right">
<p>Slice: 128</p>
<p>Origin: UAE</p>
<p>Remark: System In Good Working Condition</p>
</div>
</div>
To Know more Call #8766474892
</div>
</div>
</div>
<div class="slider__nav">
<a class="slider__navlink" href="#slides__1"></a>
<a class="slider__navlink" href="#slides__2"></a>
<a class="slider__navlink" href="#slides__3"></a>
<a class="slider__navlink" href="#slides__4"></a>
</div>
</div>
</div>
The main problem is that the slides div have an overflow-x:scroll , which keeps the previous/next links inside the container while your arrow icons are on the outside, so when you click on them you don't click on the link at all.
Also it is not a good practice to have many previous/next links, you only need one.
This is what I updated
Added simple dynamic js function to handle prev/next clicks
Update a.slider prev/next styles including before/after
Previous/next links moved to to the box-container
Note: I didn't hide the next arrow icon when it is the last slide or hide the prev arrow icon when it is the first slide, but you can add it easily.
function nextPrev(type) {
const slides = document.querySelector(".slides");
const slideWidth = document.querySelector(".slide").offsetWidth;
const scrolLeft =
slides.scrollLeft + (type === "next" ? slideWidth : -slideWidth);
slides.scrollTo({
left: scrolLeft,
behavior: "smooth",
});
}
.container {
padding: 80px 7%;
position: relative;
font-family: "Open Sans", sans-serif;
}
.details {
display: flex;
justify-content: space-between;
margin: 20px 0px 30px 0px;
color: white;
}
.right {
max-width: 50%;
}
.container .box-container .box {
box-shadow: 0 5px 10px rgba(0, 0, 0, 0.3);
background: #0d1b2a;
padding: 15px;
margin: 40px 0;
display: flex;
align-items: center;
flex-wrap: wrap;
gap: 15px;
}
.container .box-container .box .image-container {
flex: 1 1 500px;
display: flex;
align-items: center;
gap: 15px;
}
.container .box-container .box .content {
flex: 1 1 350px;
}
.container .box-container .box .image-container .small-image {
width: 20%;
}
.container .box-container .box .image-container .big-image {
width: 80%;
}
.container .box-container .box .image-container .small-image img {
width: 100%;
padding: 10px;
border: 1px solid rgba(255, 255, 255, 0.3);
cursor: pointer;
}
.container .box-container .box .image-container .small-image img:hover {
background: rgba(167, 167, 167, 0.2);
}
.container .box-container .box .image-container .big-image img {
width: 95%;
padding: 20px;
filter: drop-shadow(0 5px 10px rgba(0, 0, 0, 0.2));
}
.container .box-container .box .content h3 {
color: rgb(255, 255, 255);
font-size: 25px;
}
.hide-1 {
background-color: transparent;
padding: 5px 10px;
border: 1px solid rgb(255, 255, 255);
color: rgb(255, 255, 255);
}
.product {
height: 100vh;
}
#media only screen and (max-width: 370px) {
.details {
flex-direction: column;
}
.hide-1 {
font-size: 0.8em;
}
}
/* --------------------------------------- */
html,
body {
height: 100%;
margin: 0px;
}
.slider {
width: 100%;
border-radius: 20px;
overflow: hidden;
}
.slides {
display: flex;
overflow-x: scroll;
position: relative;
scroll-behavior: smooth;
scroll-snap-type: x mandatory;
}
.slide:nth-of-type(even) {
background-color: rgb(250, 246, 212);
}
.slide {
display: flex;
justify-content: center;
align-items: center;
flex-shrink: 0;
width: 100%;
height: 400px;
scroll-snap-align: center;
margin-right: 0px;
box-sizing: border-box;
background: white;
transform-origin: center center;
transform: scale(1);
}
.slide__text {
font-size: 40px;
font-weight: bold;
font-family: sans-serif;
}
.slide a {
background: none;
border: none;
}
a.slide__prev,
a.slide__next {
position: absolute;
border: solid black;
border-width: 0 4px 4px 0;
top: 48%;
width: 35px;
height: 35px;
}
a.slide__prev {
transform: rotate(135deg);
-webkit-transform: rotate(135deg);
left: 2%;
}
a.slide__next {
transform: rotate(-45deg);
-webkit-transform: rotate(-45deg);
right: 2%;
}
.slider::before,
.slider::after {
content: "";
z-index: 1;
background: none;
pointer-events: none;
}
.slider__nav {
box-sizing: border-box;
position: absolute;
bottom: 5%;
left: 50%;
width: 200px;
margin-left: -100px;
text-align: center;
}
.slider__navlink {
display: inline-block;
height: 15px;
width: 15px;
border-radius: 50%;
background-color: black;
margin: 0 10px 0 10px;
}
.read-article {
position: absolute;
top: 10px;
left: 10px;
z-index: 999;
color: #000;
background: white;
padding: 10px 20px;
border-radius: 10px;
font-family: arial;
text-decoration: none;
box-shadow: rgb(50 50 93 / 25%) 0 0 100px -20px,
rgb(0 0 0 / 30%) 0 0 60px -15px;
}
.read-article:hover {
background: #d5d5d5;
box-shadow: rgb(50 50 93 / 25%) 0 0 100px -20px,
rgb(0 0 0 / 30%) 0 0 60px 0px;
}
iframe[sandbox] .read-article {
display: none;
}
<div class="container slider-container">
<div class="box-container slider">
<div class="slides">
<div class="box slide" id="slides__1">
<div class="image-container">
<div class="small-image">
<img src="images/image_11.png" class="small-img-1" alt="" />
<img src="images/image_12.png" class="small-img-1" alt="" />
<img src="images/image_13.png" class="small-img-1" alt="" />
<img src="images/image_14.png" class="small-img-1" alt="" />
</div>
<div class="big-image">
<img src="images/image_11.png" class="big-img-1" alt="" />
</div>
</div>
<div class="content">
<h3>Phillips</h3>
<div class="details">
<div class="left">
<p>ID: Mp2223-0</p>
<p>Modality: CT</p>
<p>Model: Ingenuity</p>
<p>YOM: 2016</p>
</div>
<div class="right">
<p>Slice: 128</p>
<p>Origin: UAE</p>
<p>Remark: System In Good Working Condition</p>
</div>
</div>
To Know more Call #8766474892
</div>
</div>
<div class="box slide" id="slides__2">
<div class="image-container">
<div class="small-image">
<img src="images/image_11.png" class="small-img-2" alt="" />
<img src="images/image_12.png" class="small-img-2" alt="" />
<img src="images/image_13.png" class="small-img-2" alt="" />
<img src="images/image_14.png" class="small-img-2" alt="" />
</div>
<div class="big-image">
<img src="images/image_11.png" class="big-img-2" alt="" />
</div>
</div>
<div class="content">
<h3>Phillips</h3>
<div class="details">
<div class="left">
<p>ID: Mp2223-0</p>
<p>Modality: CT</p>
<p>Model: Ingenuity</p>
<p>YOM: 2016</p>
</div>
<div class="right">
<p>Slice: 128</p>
<p>Origin: UAE</p>
<p>Remark: System In Good Working Condition</p>
</div>
</div>
To Know more Call #8766474892
</div>
</div>
<div class="box slide" id="slides__3">
<div class="image-container">
<div class="small-image">
<img src="images/image_11.png" class="small-img-3" alt="" />
<img src="images/image_12.png" class="small-img-3" alt="" />
<img src="images/image_13.png" class="small-img-3" alt="" />
<img src="images/image_14.png" class="small-img-3" alt="" />
</div>
<div class="big-image">
<img src="images/image_11.png" class="big-img-3" alt="" />
</div>
</div>
<div class="content">
<h3>Phillips</h3>
<div class="details">
<div class="left">
<p>ID: Mp2223-0</p>
<p>Modality: CT</p>
<p>Model: Ingenuity</p>
<p>YOM: 2016</p>
</div>
<div class="right">
<p>Slice: 128</p>
<p>Origin: UAE</p>
<p>Remark: System In Good Working Condition</p>
</div>
</div>
To Know more Call #8766474892
</div>
</div>
<div class="box slide" id="slides__4">
<div class="image-container">
<div class="small-image">
<img src="images/image_21.png" class="small-img-4" alt="" />
<img src="images/image_22.png" class="small-img-4" alt="" />
<img src="images/image_23.png" class="small-img-4" alt="" />
<img src="images/image_24.png" class="small-img-4" alt="" />
</div>
<div class="big-image">
<img src="images/image_11.png" class="big-img-4" alt="" />
</div>
</div>
<div class="content">
<h3>Phillips</h3>
<div class="details">
<div class="left">
<p>ID: Mp2223-0</p>
<p>Modality: CT</p>
<p>Model: Ingenuity</p>
<p>YOM: 2016</p>
</div>
<div class="right">
<p>Slice: 128</p>
<p>Origin: UAE</p>
<p>Remark: System In Good Working Condition</p>
</div>
</div>
To Know more Call #8766474892
</div>
</div>
</div>
<a
class="slide__prev"
href="javascript:void(0);"
onclick="nextPrev('prev')"
title="Prev"
></a>
<a
class="slide__next"
href="javascript:void(0);"
onclick="nextPrev('next')"
title="Next"
></a>
<div class="slider__nav">
<a class="slider__navlink" href="#slides__1"></a>
<a class="slider__navlink" href="#slides__2"></a>
<a class="slider__navlink" href="#slides__3"></a>
<a class="slider__navlink" href="#slides__4"></a>
</div>
</div>
</div>
I am trying to implement a contact us page. the heading here takes only the intended space but the div takes up extra vertical space. Where did I go wrong?
section {
display: flex;
flex-wrap: wrap;
width: 99vw;
height: 96vh;
padding-top: 4vh;
}
#heading {
width: 100%;
line-height: 0.7em;
}
h1 {
display: inline;
height: 100%;
font-size: 1rem;
}
<section>
<div id="heading">
<h1>Contact Us</h1>
</div>
<div id="media_container">
<img class="soc_med" src="fb.png" alt="fb">
<img class="soc_med" src="instagram.png" alt="insta">
<img class="soc_med" src="linkedin.png" alt="LinkedIn">
<img class="soc_med" src="email.png" alt="email">
</div>
</section>
Just remove the height from the section
section{
display: flex;
flex-wrap: wrap;
width: 99vw;
padding-top: 4vh;
}
#heading{
width: 100%;
line-height: 0.7em;
}
h1{
display: inline;
height: 100%;
font-size: 1rem;
}
<section>
<div id = "heading">
<h1>Contact Us</h1>
</div>
<div id = "media_container">
<img class="soc_med" src="fb.png" alt="fb">
<img class="soc_med" src="instagram.png" alt="insta">
<img class="soc_med" src="linkedin.png" alt="LinkedIn">
<img class="soc_med" src="email.png" alt="email">
</div>
</section>
Just add margin: 0; to html, body to avoid the default margins on these elements which are the cause for your problem:
html,
body {
margin: 0;
}
section {
display: flex;
flex-wrap: wrap;
width: 99vw;
height: 96vh;
padding-top: 4vh;
}
#heading {
width: 100%;
line-height: 0.7em;
}
h1 {
display: inline;
height: 100%;
font-size: 1rem;
}
<section>
<div id="heading">
<h1>Contact Us</h1>
</div>
<div id="media_container">
<img class="soc_med" src="fb.png" alt="fb">
<img class="soc_med" src="instagram.png" alt="insta">
<img class="soc_med" src="linkedin.png" alt="LinkedIn">
<img class="soc_med" src="email.png" alt="email">
</div>
</section>
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; }
trying to make a simple project where the left side will be navigating and the right main content. The problem is that I do not want to use the float: left, float: right function. Is there any other option to get this effect? Below is the photo:
enter image description here
* {
margin: 0;
padding: 0;
}
html {
font-size: 62.5%;
}
body {
font-size: 1.6rem;
font-family: Arial, Arial, Helvetica, sans-serif;
}
/* product section */
.products {
display: flex;
flex-wrap: wrap;
max-width: 853px;
margin: 0 auto;
}
.product-card {
display: flex;
flex-direction: column;
padding: 2%;
flex: 1 16%;
background-color: #FFF;
box-shadow: 0px 0px 1px 0px rgba(0,0,0,0.25);
}
.product-image img {
width: 100%;
}
.product-info {
margin-top: auto;
padding-top: 20px;
text-align: center;
}
h5 {
color: #C00;
font-size: 1.2rem;
font-weight: bold;
text-align: center;
text-transform: uppercase;
}
/* product section end */
.nav {
max-width: 853px;
margin: 0 auto;
}
.nav ul{
list-style: none;
width: 150px;
font-size: 1em;
padding: 0;
}
.nav li a{
text-decoration: none;
display: block;
}
.nav .parent li a{
padding: 10px 12px 10px 20px;
background: #429840;
color: white;
border-bottom:1px solid #eee;
}
.nav .child li a{ background: #ddd; color:#333;}
.nav .parent a:hover{ background: #429855;}
.nav .child a:hover{ background: #429855;}
ul.parent > li:hover > ul.child{
display: block;
position: absolute;
left: 150px; top: 0;
}
ul.parent > li{ position: relative;}
ul.child{ display: none; }
.plus{ float: right; }
<div class="nav">
<ul class="parent">
<li>Home</li>
<li>About <span class="plus">+</span>
<ul class="child">
<li>What We do?</li>
<li>Awords</li>
</ul>
</li>
<li>Products <span class="plus">+</span>
<ul class="child">
<li>Mobile</li>
<li>Desktop</li>
</ul>
</li>
<li>Contact</li>
</ul>
</div>
<section class="products">
<div class="product-card">
<div class="product-image">
<img src="https://www.ayearofboxes.com/wp-content/themes/ayearofboxes/assets/svg/box-closed.svg" alt="90gsm">
</div>
<div class="product-info">
<h5>box1</h5>
</div>
</div>
<div class="product-card">
<div class="product-image">
<img src="https://www.ayearofboxes.com/wp-content/themes/ayearofboxes/assets/svg/box-closed.svg" alt="90gsm">
</div>
<div class="product-info">
<h5>box2</h5>
</div>
</div>
<div class="product-card">
<div class="product-image">
<img src="https://www.ayearofboxes.com/wp-content/themes/ayearofboxes/assets/svg/box-closed.svg" alt="90gsm">
</div>
<div class="product-info">
<h5>box3</h5>
</div>
</div>
<div class="product-card">
<div class="product-image">
<img src="https://www.ayearofboxes.com/wp-content/themes/ayearofboxes/assets/svg/box-closed.svg" alt="90gsm">
</div>
<div class="product-info">
<h5>box4</h5>
</div>
</div>
<div class="product-card">
<div class="product-image">
<img src="https://www.ayearofboxes.com/wp-content/themes/ayearofboxes/assets/svg/box-closed.svg" alt="90gsm">
</div>
<div class="product-info">
<h5>box5</h5>
</div>
</div>
<div class="product-card">
<div class="product-image">
<img src="https://www.ayearofboxes.com/wp-content/themes/ayearofboxes/assets/svg/box-closed.svg" alt="90gsm">
</div>
<div class="product-info">
<h5>box6</h5>
</div>
</div>
<div class="product-card">
<div class="product-image">
<img src="https://www.ayearofboxes.com/wp-content/themes/ayearofboxes/assets/svg/box-closed.svg" alt="90gsm">
</div>
<div class="product-info">
<h5>box7</h5>
</div>
</div>
<div class="product-card">
<div class="product-image">
<img src="https://www.ayearofboxes.com/wp-content/themes/ayearofboxes/assets/svg/box-closed.svg" alt="90gsm">
</div>
<div class="product-info">
<h5>box8</h5>
</div>
</div>
<div class="product-card">
<div class="product-image">
<img src="https://www.ayearofboxes.com/wp-content/themes/ayearofboxes/assets/svg/box-closed.svg" alt="90gsm">
</div>
<div class="product-info">
<h5>box9</h5>
</div>
</div>
<div class="product-card">
<div class="product-image">
<img src="https://www.ayearofboxes.com/wp-content/themes/ayearofboxes/assets/svg/box-closed.svg" alt="90gsm">
</div>
<div class="product-info">
<h5>box10</h5>
</div>
</div>
</section>
I tried to use a flexbox, but everything starts break...
You just need to wrap everything and flex it too.
* {
margin: 0;
padding: 0;
}
html {
font-size: 62.5%;
}
body {
font-size: 1.6rem;
font-family: Arial, Arial, Helvetica, sans-serif;
}
/* product section */
.wrapper {
display: flex;
flex-wrap: nowrap;
flex-direction: row;
}
.products {
display: flex;
flex-wrap: wrap;
max-width: 853px;
margin: 0 auto;
}
.product-card {
display: flex;
flex-direction: column;
padding: 2%;
flex: 1 16%;
background-color: #FFF;
box-shadow: 0px 0px 1px 0px rgba(0, 0, 0, 0.25);
}
.product-image img {
width: 100%;
}
.product-info {
margin-top: auto;
padding-top: 20px;
text-align: center;
}
h5 {
color: #C00;
font-size: 1.2rem;
font-weight: bold;
text-align: center;
text-transform: uppercase;
}
/* product section end */
.nav {
max-width: 853px;
margin: 0 auto;
}
.nav ul {
list-style: none;
width: 150px;
font-size: 1em;
padding: 0;
}
.nav li a {
text-decoration: none;
display: block;
}
.nav .parent li a {
padding: 10px 12px 10px 20px;
background: #429840;
color: white;
border-bottom: 1px solid #eee;
}
.nav .child li a {
background: #ddd;
color: #333;
}
.nav .parent a:hover {
background: #429855;
}
.nav .child a:hover {
background: #429855;
}
ul.parent>li:hover>ul.child {
display: block;
position: absolute;
left: 150px;
top: 0;
}
ul.parent>li {
position: relative;
}
ul.child {
display: none;
}
.plus {
float: right;
}
<div class="wrapper">
<div class="nav">
<ul class="parent">
<li>Home</li>
<li>About <span class="plus">+</span>
<ul class="child">
<li>What We do?</li>
<li>Awords</li>
</ul>
</li>
<li>Products <span class="plus">+</span>
<ul class="child">
<li>Mobile</li>
<li>Desktop</li>
</ul>
</li>
<li>Contact</li>
</ul>
</div>
<section class="products">
<div class="product-card">
<div class="product-image">
<img src="https://www.ayearofboxes.com/wp-content/themes/ayearofboxes/assets/svg/box-closed.svg" alt="90gsm">
</div>
<div class="product-info">
<h5>box1</h5>
</div>
</div>
<div class="product-card">
<div class="product-image">
<img src="https://www.ayearofboxes.com/wp-content/themes/ayearofboxes/assets/svg/box-closed.svg" alt="90gsm">
</div>
<div class="product-info">
<h5>box2</h5>
</div>
</div>
<div class="product-card">
<div class="product-image">
<img src="https://www.ayearofboxes.com/wp-content/themes/ayearofboxes/assets/svg/box-closed.svg" alt="90gsm">
</div>
<div class="product-info">
<h5>box3</h5>
</div>
</div>
<div class="product-card">
<div class="product-image">
<img src="https://www.ayearofboxes.com/wp-content/themes/ayearofboxes/assets/svg/box-closed.svg" alt="90gsm">
</div>
<div class="product-info">
<h5>box4</h5>
</div>
</div>
<div class="product-card">
<div class="product-image">
<img src="https://www.ayearofboxes.com/wp-content/themes/ayearofboxes/assets/svg/box-closed.svg" alt="90gsm">
</div>
<div class="product-info">
<h5>box5</h5>
</div>
</div>
<div class="product-card">
<div class="product-image">
<img src="https://www.ayearofboxes.com/wp-content/themes/ayearofboxes/assets/svg/box-closed.svg" alt="90gsm">
</div>
<div class="product-info">
<h5>box6</h5>
</div>
</div>
<div class="product-card">
<div class="product-image">
<img src="https://www.ayearofboxes.com/wp-content/themes/ayearofboxes/assets/svg/box-closed.svg" alt="90gsm">
</div>
<div class="product-info">
<h5>box7</h5>
</div>
</div>
<div class="product-card">
<div class="product-image">
<img src="https://www.ayearofboxes.com/wp-content/themes/ayearofboxes/assets/svg/box-closed.svg" alt="90gsm">
</div>
<div class="product-info">
<h5>box8</h5>
</div>
</div>
<div class="product-card">
<div class="product-image">
<img src="https://www.ayearofboxes.com/wp-content/themes/ayearofboxes/assets/svg/box-closed.svg" alt="90gsm">
</div>
<div class="product-info">
<h5>box9</h5>
</div>
</div>
<div class="product-card">
<div class="product-image">
<img src="https://www.ayearofboxes.com/wp-content/themes/ayearofboxes/assets/svg/box-closed.svg" alt="90gsm">
</div>
<div class="product-info">
<h5>box10</h5>
</div>
</div>
</section>
</div>
If you use position absolute on each of the sections you will be able to use left:0 and right:0. See below and hope that helps.
.nav {
max-width: 853px;
margin: 0 auto;
width: 200px;
position: absolute;
left: 0;
z-index:2;
}
section.products {
width: calc(100% - 200px);
position: absolute;
right: 0;
z-index: 1;
}