<!-- Carousel 2 -->
<div class="image-item">
<div class="carousel">
<div class="carousel-container">
<div class="image-wrapper">
<div class="carousel-counter">1 / 4</div>
<div class="carousel-slides">
<div class="carousel-slide active">
<img
src="https://i.ibb.co/MP25TzB/Chris-and-Anna-1-copy.webp"
alt="Beautiful skies with some sushine"
/>
<h3>Chris and Anna</h3>
<p>Forever starts here 💍</p>
</div>
<div class="carousel-slide">
<img
src="https://i.ibb.co/JR0SjM1/Chris-and-Anna-2-copy.webp"
alt="Beautiful skies with some sushine"
/>
<h3>Chris and Anna</h3>
<p>Two hearts, one promise ❤️</p>
</div>
<div class="carousel-slide">
<img
src="https://i.ibb.co/CtG7B4z/Chris-and-Anna-3-copy.webp"
alt="Beautiful skies with some sushine"
/>
<h3>Chris and Anna</h3>
<p>Brothers, united for the big day 🤵♂️</p>
</div>
<div class="carousel-slide">
<img
src="https://i.ibb.co/vqcxBG0/Chris-and-Anna-4-copy.webp"
alt="Beautiful skies with some sushine"
class="vertical"
/>
<h3>Chris and Anna</h3>
<p>Her squad, his crew, together for the love of two 👰♀️🤵♂️</p>
</div>
</div>
</div>
<button class="carousel-btn prev">❮</button>
<button class="carousel-btn next">❯</button>
<div class="carousel-dots">
<span class="dot active"></span>
<span class="dot"></span>
<span class="dot"></span>
<span class="dot"></span>
</div>
</div>
</div>
</div>
<!-- Add more carousels like the ones above for future events -->
</section>
/* Photo grid */
.image-grid {
display: grid;
grid-template-columns: repeat(2, 1fr);
gap: 20px;
padding: 40px;
background-color: black;
}
.image-item {
text-align: center;
color: white;
}
.image-item img {
max-width: 100%; /* Prevents the image from exceeding its container's width */
height: auto;
aspect-ratio: 3 / 2; /* Maintain aspect ratio */
object-fit: cover;
border-radius: 10px;
max-height: 400px; /* Adjust this value to control the height of the images */
box-shadow: 0px 4px 15px rgba(0, 0, 0, 0.5);
margin-bottom: 15px;
}
.image-item h3 {
font-size: 1.2em;
margin: 10px 0;
}
.image-item p {
font-size: 0.9em;
color: #ccc;
}
/* Carousel Styles */
.carousel {
position: relative; /* Make this container the reference for absolutely positioned elements */
width: 100%;
margin: 0 auto;
}
.carousel-container {
position: relative; /* Ensure the container is the reference for absolute positioning */
overflow: hidden; /* Prevent overflow of slides or elements */
}
.carousel-slides {
display: flex;
transition: transform 0.5s ease;
}
.carousel-slide {
position: relative; /* Ensure the slide is the reference for absolute positioning */
display: flex;
justify-content: center;
align-items: center;
flex-basis: 100%; /* Ensures each slide takes up the full width of the carousel */
}
.carousel-slide p {
flex-basis: auto; /* Let the text adapt to its content size */
}
.image-wrapper {
position: relative;
display: inline-block;
overflow: hidden;
}
.image-wrapper img {
display: block;
width: 100%;
height: auto;
object-fit: cover;
border-radius: 10px;
max-height: 400px;
box-shadow: 0px 4px 15px rgba(0, 0, 0, 0.5);
z-index: 0;
}
/* Horizontal images (3:2 aspect ratio) */
.carousel-slide img.horizontal {
aspect-ratio: 3 / 2; /* Force 3:2 aspect ratio */
object-fit: cover; /* Crop to fit */
width: 100%; /* Ensure the image fills the container width */
height: auto; /* Maintain aspect ratio */
border-radius: 10px;
box-shadow: 0px 4px 15px rgba(0, 0, 0, 0.5);
}
/* Vertical images (2:3 aspect ratio) */
.carousel-slide img.vertical {
aspect-ratio: 2 / 3; /* Force 2:3 aspect ratio */
object-fit: contain; /* Maintain aspect ratio without cropping */
width: 100%; /* Ensure the image fills the container width */
height: auto; /* Maintain aspect ratio */
border-radius: 10px;
box-shadow: 0px 4px 15px rgba(0, 0, 0, 0.5);
}
.carousel-slide img {
max-width: 100%;
height: auto;
object-fit: contain; /*to maintain aspect ratio */
border-radius: 10px;
max-height: 400px;
margin-bottom: 15px;
box-shadow: 0px 4px 15px rgba(0, 0, 0, 0.5);
flex-basis: auto; /* Allow images to take up only as much space as needed */
}
/* Counter */
.carousel-counter {
position: absolute;
top: 10px; /* Move the counter to the top */
left: 10px; /* Move the counter to the left */
background: rgba(0, 0, 0, 0.5);
color: white;
padding: 5px 10px;
border-radius: 5px;
font-size: 14px;
z-index: 10;
pointer-events: none; /* Prevent interaction */
}
/* Navigation Buttons */
.carousel-btn {
position: absolute;
top: 50%;
transform: translateY(-50%);
background-color: rgba(0, 0, 0, 0.5);
color: white;
border: none;
padding: 10px;
cursor: pointer;
z-index: 10;
font-size: 24px;
}
.carousel-btn.prev {
left: 10px;
this is where you can see the problem
codepen
–if you’re on mobile might not see it correctly i have not optimized for mobile yet–
i have tried wrap the image and the carousel counter in a new relatively positioned element, tried repositioning .carousel-counter in the css. i probably did not wrap correctly but i cannot find the mistake.
2
Answers
modify this lines of code in your CSS file :
if you also want to stop paragraph element from affecting parent width apply this to the paragraph:
A simple way is only editing CSS carousel-slides Class and carousel-dots Class.