This project demonstrates a pure CSS implementation of a 3D slider, showcasing the power of modern CSS techniques for creating engaging, interactive user interfaces without JavaScript.
- Overview
- File Structure
- How It Works
- Key CSS Techniques
- Responsive Design
- Browser Compatibility
- Customization
The 3D slider creates an impressive rotating carousel effect using only HTML and CSS. It features:
- A circular arrangement of images in 3D space
- Automatic rotation animation
- Responsive design that adapts to different screen sizes
- Custom typography and layout
├── index.html
├── css/
│ ├── base.css
│ └── slider.css
├── images/
│ ├── dragon_1.jpg
│ ├── dragon_2.jpg
│ └── ...
└── fonts/
├── ICARubrikBold.woff
├── Poppins-Regular.woff
└── Poppins-Bold.woff
index.html: Main HTML structurebase.css: General styling and background setupslider.css: 3D slider specific styles and animations
-
HTML Structure: The slider is created using nested
<div>elements. Each image is contained within an.itemdiv inside the main.slidercontainer. -
3D Space: The
.slidercontainer establishes a 3D space using CSStransform-styleandperspectiveproperties. -
Item Positioning: Each
.itemis positioned in a circular arrangement using CSStransformwithrotateY()andtranslateZ(). -
Animation: The entire slider rotates using a CSS
@keyframesanimation, creating the carousel effect.
.banner .slider {
transform-style: preserve-3d;
transform: perspective(62.5rem);
}This creates a 3D space for child elements.
.banner .slider .item {
transform: rotateY(calc((var(--position) - 1) * (360 / var(--quantity)) * 1deg))
translateZ(34.38rem);
}This positions each item in a circular arrangement. The --position and --quantity CSS variables allow for dynamic positioning.
@keyframes autoRun {
from { transform: perspective(62.5rem) rotateX(-12deg) rotateY(0deg); }
to { transform: perspective(62.5rem) rotateX(-12deg) rotateY(360deg); }
}This animation rotates the entire slider, creating the carousel effect.
The slider adapts to different screen sizes using media queries:
- On screens smaller than 1024px, the slider size and positioning are adjusted.
- On screens smaller than 768px, further size reductions are applied.
This ensures the slider looks good on devices ranging from desktop to mobile.
This slider uses modern CSS properties and should work well in recent versions of major browsers. However, some features may not be supported in older browsers. Consider using autoprefixers or fallbacks for maximum compatibility.
To customize the slider:
- Adjust the number of items by changing the
--quantityvariable in the HTML. - Modify the rotation speed by changing the animation duration in
.banner .slider. - Alter the size and positioning of items by adjusting the
width,height, andtranslateZvalues. - Change the background and styling in
base.cssandslider.css.
Feel free to experiment with different images, colors, and layouts to make the slider fit your project's needs!
This project demonstrates the capabilities of modern CSS for creating complex, interactive UI elements without relying on JavaScript. It's a great starting point for learning about 3D transforms and animations in CSS.