Creating a carousel using CSS can be achieved using CSS animations and transforms. Here is an example of how to create a basic carousel using CSS:
HTML:
<div class="carousel-container">
<div class="carousel">
<div class="slide">
<img src="" alt="Image 1">
</div>
<div class="slide">
<img src="" alt="Image 2">
</div>
<div class="slide">
<img src="image3.jpg" alt="Image 3">
</div>
</div>
</div>
</div>
CSS:
.carousel-container {
width: 100%;
overflow: hidden;
}
.carousel {
display: flex;
width: 300%;
animation: slide 10s infinite;
}
.slide {
width: 33.33%;
padding: 10px;
box-sizing: border-box;
}
.slide img {
width: 100%;
}
@keyframes slide {
0% {
transform: translateX(0);
}
33.33% {
transform: translateX(-100%);
}
66.66% {
transform: translateX(-200%);
}
100% {
transform: translateX(0);
}
}
In this example, we have a container with the class "carousel-container" that has an overflow of hidden to hide the overflow of the carousel. The carousel itself has a width of 300% to accommodate the width of all the slides, and a flex display to align the slides horizontally. The slides have a width of 33.33% to ensure that all three slides fit within the carousel container. The slide images have a width of 100% to fill the width of their respective slides.
The @keyframes rule defines the animation for the carousel, where we translate the carousel horizontally by 100% for each slide, and then back to 0% to create the carousel effect. The animation is set to repeat infinitely with a duration of 10 seconds.
Note that this is a basic example, and you can modify the styles and animation to fit your specific needs and design.