Problem: 3D Rotating Image Carousel
Problem description
Given an HTML page with a <div class="carousel"> consisting of multiple <div class="carousel-item"> elements, each with an image. Write CSS to:
Set
.carouselto a fixed size (e.g.,width: 400px; height: 300px;), center it, establishperspective: 1000px, and apply aspinanimation rotating aroundY.Configure
.carouselwithtransform-style: preserve-3dto maintain 3D context.Style
.carousel-itemto beposition: absolute; width: 200px; height: 150px; top: 50%; left: 50%; transform-style: preserve-3d;.Position each item around the ring by applying
transform: rotateY(N * 60deg) translateZ(300px) translateX(-50%) translateY(-50%)for each child (where N is its zero-based index).Define
@keyframes spinto rotate the carousel fromrotateY(0deg)torotateY(-360deg).Apply the
spinanimation to.carouselwith a duration of20s, timing functionlinear, and infinite iteration.
Goal
Write CSS rules to create a full 3D image carousel rotating infinitely around its vertical axis.
Constraints
Use only CSS (no JavaScript).
Carousel dimensions should be
width: 400px; height: 300px;.Perspective should be
1000pxon.carousel.Carousel
transform-styleshould bepreserve-3d.Number of items should be 6—each rotated by increments of
60degaround the Y-axis and translated outward by300px.Each item should be centered via
translate(-50%, -50%)after translation.Animation name should be
spin.Animation duration should be
20s.Animation timing function should be
linear.Animation iteration count should be
infinite.
Sample visual output
Here’s what the output would look like:
Good luck trying the problem! If you’re unsure how to proceed, check the Solution.
Problem: 3D Rotating Image Carousel
Problem description
Given an HTML page with a <div class="carousel"> consisting of multiple <div class="carousel-item"> elements, each with an image. Write CSS to:
Set
.carouselto a fixed size (e.g.,width: 400px; height: 300px;), center it, establishperspective: 1000px, and apply aspinanimation rotating aroundY.Configure
.carouselwithtransform-style: preserve-3dto maintain 3D context.Style
.carousel-itemto beposition: absolute; width: 200px; height: 150px; top: 50%; left: 50%; transform-style: preserve-3d;.Position each item around the ring by applying
transform: rotateY(N * 60deg) translateZ(300px) translateX(-50%) translateY(-50%)for each child (where N is its zero-based index).Define
@keyframes spinto rotate the carousel fromrotateY(0deg)torotateY(-360deg).Apply the
spinanimation to.carouselwith a duration of20s, timing functionlinear, and infinite iteration.
Goal
Write CSS rules to create a full 3D image carousel rotating infinitely around its vertical axis.
Constraints
Use only CSS (no JavaScript).
Carousel dimensions should be
width: 400px; height: 300px;.Perspective should be
1000pxon.carousel.Carousel
transform-styleshould bepreserve-3d.Number of items should be 6—each rotated by increments of
60degaround the Y-axis and translated outward by300px.Each item should be centered via
translate(-50%, -50%)after translation.Animation name should be
spin.Animation duration should be
20s.Animation timing function should be
linear.Animation iteration count should be
infinite.
Sample visual output
Here’s what the output would look like:
Good luck trying the problem! If you’re unsure how to proceed, check the Solution.