Responsive slider using CSS3. A selection of responsive sliders Cross-browser slider

November 4, 2019 Post has been updated

Yuri Nemets

Pure CSS sliders + bonus slider

CSS sliders have some advantages over Javascript sliders. One of these benefits is loading speed. Not only are images for sliders used in large sizes (if there is no optimization for different screens), but also some time is spent loading scripts. But in the article you will only see sliders using pure CSS.

Here's what I found on a website about sliders:

1. CSS3 image slider

A CSS slider that uses radio buttons to navigate slides. These radio buttons are located under the sliders. Also, in addition to radio buttons, navigation is carried out using arrows on the left and right. To keep track of which image is currently displayed, the :checked pseudo-classes are used.

2. CSS3 image slider with thumbnails

Unlike the previous CSS slider, here instead of radio buttons at the bottom there are thumbnails of all images, which is also convenient when creating an image gallery. The images change with a peculiar effect: they smoothly disappear when enlarged.

3. Gallery with CSS

But this CSS slider is perfect for sales pages. As a rule, when developing landing pages (selling pages), many web developers place a slider at the very beginning, so that on the first screen (without scrolling) the visitor immediately sees all the benefits that are available to him on this page. Besides everything, this slider is adaptive, which is also nice.

4. CSS slider without links

I would like to note right away that this slider does not use links! By default, in addition to the main image (slide), 2 more slides are visible. They are located behind the main one. Changing slides occurs in a beautiful mode: first, two slides are moved apart and the slide that will then become the main one becomes centered. The slide is then enlarged and placed in front of the others.

5. Responsive CSS3 Slider

Another adaptive slider, the control of which is based on radio buttons. To see how this slider will look on different devices ah - You can either change the browser window yourself, or on the page with the slider there are special icons for different devices, by clicking on which you will see what the slider will look like on a computer, tablet or smartphone.

***BONUS SLIDER***

In addition to all the sliders presented above, I want to please you with one more. This slider is perfect for creating an image gallery. You can’t explain in words what he does, so it’s better to watch everything in the video:

Conclusion

Using sliders, you can beautifully design image galleries, placing them more compactly, insert a slider into the first screen (the part of the page that is visible without scrolling) of the sales page to immediately show the visitor the main benefits that he will receive. You can still find a lot of ways where and how you can use sliders, but one thing is clear - they are useful when used correctly.

Points that were discussed in the article.

Currently, a slider - carousel - is a functionality that is simply necessary to have on a business website, portfolio website or any other resource. Along with full-screen image sliders, horizontal carousel sliders fit well into any web design.

Sometimes the slider should occupy one third of the site page. Here the carousel slider is used with transition effects and responsive layouts. E-commerce sites use a carousel slider to display multiple photos in individual posts or pages. The slider code can be freely used and modified according to your needs.

Using JQuery together with HTML5 And CSS3, you can make your pages more interesting by providing them with unique effects and draw the attention of visitors to a specific area of ​​the site.

Slick – modern carousel slider plugin

Slick is a freely distributed jquery plugin whose developers claim that their solution will satisfy all your slider requirements. Adaptive slider – carousel can work in “ tiles"for mobile devices, and, in the " drag and drop"for the desktop version.

Contains a transition effect " attenuation», interesting opportunity « center mode", lazy loading of images with auto-scrolling. Updated functionality includes adding slides and a slide filter. All to ensure that you configure the plugin according to your requirements.

Owl Carousel 2.0 – jQuery – plugin for use on touch devices

This plugin has a large set of functions, suitable for both beginners and experienced developers. This is an updated version of the carousel slider. His predecessor had the same name.

The slider has some built-in plugins to improve the overall functionality. Animation, video playback, slider autoplay, lazy loading, automatic height adjustment - the main features.

Feature support drag and drop included for more convenient use of the plugin on mobile devices.
The plugin is perfect for displaying large images even on small screens of mobile devices.

A fairly small, but functionally rich jquery plugin that allows you to place a slider on a page - a carousel, which has a small core and does not consume a lot of site resources. The plugin can be used to display vertical and horizontal sliders, with animation and create sets of images from the gallery.

AnoSlide – Ultra compact responsive jQuery slider

Ultra compact jQuery slider– a carousel, the functionality of which is much greater than that of a regular slider. It include preview one image, displaying multiple images in the form of a carousel and slider based on titles.

Owl Carousel – Jquery slider – carousel

– slider with support touch screens and technology drag and drop, easily integrated into HTML- code. The plugin is one of the best sliders that allow you to create beautiful carousels without any specially prepared markup.

3D gallery – carousel

Uses 3D– transitions based on CSS– styles and a little Javascript code.

Magnificent 3D carousel. It looks like this is still a beta version, because I discovered a couple of problems with it just now. If you are interested in testing and creating your own sliders, this carousel will be a great help.

Carousel using bootstrap

Responsive Slider – Carousel using technology just right for your new website.

Moving Box carousel slider based on Bootstrap framework

Most popular on portfolio and business websites. This type of slider – carousel – is often found on websites of any type.

This tiny sized slider is ready to work on devices with any screen resolution. The slider can work in both circular and carousel modes. Tiny circle presented as an alternative to other sliders of this type. Built-in support available operating systems iOS And Android.

In circular mode, the slider looks quite interesting. Excellent method support drag and drop and an automatic slide scrolling system.

A powerful, adaptive, carousel slider is perfect for a modern website. Works correctly on any device. Has horizontal and vertical modes. Its size is minimized to just 1 KB. The ultra compact plugin also has excellent smooth transitions.

Wow – slider – carousel

Contains more than 50 effects, which can help you create an original slider for your website.

Resize your browser window to see how the slider adapts. Bxslider comes with more than 50 customization options and showcases its features with various transition effects.

jCarousel - jQuery a plugin that will help organize the viewing of your images. You can easily create custom image carousels from the base shown in the example. The slider is adaptive and optimized for working on mobile platforms.

Scrollbox – jQuery plugin

Scrollbox compact plugin for creating a slider - carousel or text ticker. Key features include vertical and horizontal scrolling effects with pause on mouse over.

A simple carousel slider. If you need a fast plugin, this one is 100% suitable. Comes with only the basic features required for the slider to work.

Flexisel: Responsive JQuery Carousel Slider Plugin

The creators were inspired by an old school plugin, making a copy of it aimed at correct operation slider on mobile and tablet devices.

A responsive layout, when running on mobile devices, is different from a layout that is oriented to the size of the browser window. perfectly adapted to work on screens, both low and high resolution.

Elastislide – adaptive slider – carousel

Adapts perfectly to the size of the device screen. You can set the minimum number of images to display at a specific resolution. Works well as a carousel slider with image galleries, using a fixed wrapper along with a vertical scrolling effect.

Freely available slider from Woothemes. Rightfully considered one of the best adaptive sliders. The plugin contains several templates and will be useful for both novice users and experts.

Amazing Carousel

Amazing Carousel– adaptive image slider on jQuery. Supports many content management systems such as WordPress, Drupal And Joomla. Also supports Android And iOS and desktop versions of operating systems without any compatibility issues. Built-in amazing carousel templates allow you to use the slider in vertical, horizontal and circular modes.

Collection of free HTML and CSS slider code examples: card, comparison, fullscreen, responsive, simple, etc. Update of June 2018 collection. 7 new items.

Table of Contents

Related Articles


About the code

A set of onboarding screens in HTML/CSS/JS. A personal experiment with layering PNG icons, CSS3 transitions, & flexbox.

HTML, CSS and JavaScript information card slider.
Made by Andy Tran
November 23, 2015

Photo slider working on desktop and mobile browsers.
Made by Taron
September 29, 2014

Comparison (Before/After) Sliders


About the code

A simple and clean image comparison slider, fully responsive and touch ready made with CSS and jQuery.


About the code

A before and after slider with only html and css.


About the code

Playing around with a new idea using my two layer before/after image slider. Keeping it minimal. Keeping it vanilla. Like it if it"s useful:)

Vanilla JS, minimal, nice to look.
Made by Huw
July 3, 2017


About the code

A "split-screen" slider element with JavaScript.

A little experiment for a before & after slider all inside a SVG. Masking makes it pretty simple. Since it’s all SVG, the images and captions scale nicely together. GreenSock’s Draggable and ThrowProps plugins were used for the slider control.
Made by Craig Roblewsky
April 17, 2017

Uses customized range input for slider.
Made by Dudley Storey
October 14, 2016

Responsive image comparison slider with HTML, CSS and JavaScript.
Made by Ege Görgülü
August 3, 2016

HTML5, CSS3 and JavaScript video before-and-after comparison slider.
Made by Dudley Storey
April 24, 2016

A handy draggable slider to quickly compare 2 images, powered by CSS3 and jQuery.
Made by CodyHouse
September 15, 2014

Fullscreen Sliders

About the code

Simple slider based on radio inputs. 100% pure HTML + CSS. Works also with arrow keys.

Responsive: yes

Dependencies: -


About the code

Nice transition effect for fullscreen slider.


About the code

Horizontal parallax sliding slider with Swiper.js.


About the code

Responsive smooth 3D perspective slider on mouse move.

Fullscreen hero image slider (swipe panels theme) with HTML, CSS and JavaScript.
Made by Tobias Bogliolo
June 25, 2017

A slider interaction thing using Velocity and Velocity effects (UI Pack) to enhance the animation. Animation is triggered via arrow keys, nav click, or scrolling jack. This version includes borders as part of the interaction.
Made by Stephen Scaff
May 11, 2017

Simple slider in a minimal style to show off images. Part of the image pops out on each slide.
Made by Nathan Taylor
January 22, 2017

The thing is pretty easy customizable. You can Safely change font, font size, font color, animation speed. The first letter of a new string in array in JS will appear on a new slide. Easy to create (or delete) a new slide: 1. Add new city in the array in JS. 2. Change number of slides variable and put a new image in scss list in CSS.
Made by Ruslan Pivovarov
October 8, 2016

  1. Clip-path for image masking rectangle border (webkit only).
  2. Blend-mode for this mask.
  3. Smart color system, just put your color name and value into sass map and then add proper class with this color name to elements and everything will work!
  4. Cool credits side-menu (click small button in the center of demo).
  5. Vanilla js with just< 200 lines of code (basically it’s just adds/removes classes).
Made by Nikolay Talanov
October 7, 2016

This skewed slider with scrolling based on pure JS and CSS (without libraries).
Made by Victor Belozyorov
September 3, 2016

A slider animation with Pokemon design.
Made by Pham Mikun
August 18, 2016

HTML, CSS and JavaScritp slider with complex animation and half-collored angled text.
Made by Ruslan Pivovarov
July 13, 2016

Slider parallax effect with HTML, CSS and JavaScript.
Made by Manuel Madeira
June 28, 2016

HTML, CSS and JavaScript slider with ripple effect.
Made by Pedro Castro
May 21, 2016

Clip-Path revealing slider with HTML, CSS and JavaScript.
Made by Nikolay Talanov
May 16, 2016

GSAP + Slick slider with preview of previous/next slides.
Made by Karlo Videk
April 27, 2016

HTML, CSS and JavaScript full page slider.
Made by Joseph Martucci
February 28, 2016

Full slider prototype with HTML, CSS and JavaScript.
Made by Gluber Sampaio
January 6, 2016

A fullscreen, sort of responsive, slideshow animated with Greensocks TweenLite/Tweenmax.
Made by Arden
December 12, 2015

Made by Arden
December 5, 2015

Full-Screen slider (GSAP Timeline) #1 with HTML, CSS and JavaScript.
Made by Diaco M.Lotfollahi
November 23, 2015

HTML and CSS slider with custom effects.
Made by Nikolay Talanov
November 12, 2015

Fullscreen drag-slider with parallax with HTML, CSS and JavaScript.
Made by Nikolay Talanov
November 12, 2015

Proof of concept rotating slider. Uses clip-path and lots of math.
Made by Tyler Johnson
April 16, 2015

A simple fullscreen CSS & jQuery slider using translateX and translate3d smoothness!
Made by Joseph
August 19, 2014

Responsive Sliders

About the code

Images Opacity Slider

Images opacity slider in HTML and CSS.

Compatible browsers: Chrome, Edge, Firefox, Opera, Safari

Responsive: yes

Dependencies: -

About the code

Stacked Flexible Slides Layout

This example illustrates how to create layout of slides stacked on each other (especially useful for fade in/out transitions). It"s achieved without setting their height and avoiding position: absolute; so they are fully flexible and easy to keep in normal page flow.

Compatible browsers: Chrome, Edge, Firefox, Opera, Safari

Responsive: yes

Dependencies: -

About the code

Responsive Slider

Animated responsive slider in HTML, CSS and JavaScript.

Compatible browsers: Chrome, Edge, Firefox, Opera, Safari

Responsive: yes

Dependencies: animate.css

About the code

Slider With Masked Text

CSS only slider with masked text.

Compatible browsers: Chrome, Edge (partial), Firefox, Opera, Safari

Responsive: yes

Dependencies: -


About the code

Image and content with parallax effect.

About the code

CSS only slide gallery.

Compatible browsers: Chrome, Edge, Firefox, Opera, Safari

Responsive: yes

Dependencies: -

About the code

Pure HTML/CSS Slider

Pure HTML/CSS slider with circular SVG progress bar.

Compatible browsers: Chrome, Edge (partial), Firefox (partial), Opera, Safari

Responsive: yes

Dependencies: font-awesome.css


About the code

An experiment to create a completely responsive vertical slider with thumbnails using only CSS, and retaining the aspect ratio of the images.


About the code

A simple Flexbox image slider/carousel made with vanilla JavaScript.


About the code

This is an experiment that simulates a motion blur effect every time a slide is switched. It takes advantage of SVG Gaussian Blur filter and some CSS keyframes animation. Although the effect does not require any Javascript to properly work, in this example Javascript is only used for the slider functionality.


About the code

Cool animates slider with JS.


About the code

This is an experiment on how SVG patterns can help us create masked-like images for a CSS-only image slider.

Exploring some slider transitions. Swiper slider with parallax option enabled. Playing with CSS filters mostly here.
Made by Mirko Zorić
June 12, 2017

Simple GSAP slider with some subtle tween animations.
Made by Goran Vrban
June 9, 2017

Slider UI with HTML, CSS and JavaScript.
Made by Mergim Ujkani
June 6, 2017

Slider GSAP version 2.
Made by Em An
May 4, 2017

A little slicey transition slider using a simple add class deal. Have to smooth out the timings a bit and decide on the best approach for mobile (just stack, add touch events, make images full viewport, etc. Supports scrollwheel (scroll jacking), nav buttons and arrow keys. Can also increase the content wrapper to make the images fill viewport in their non animating state, which is kinda cool as well.
Made by Stephen Scaff
January 3, 2017

Leveraged CSS border-image & clip-path to create a slider animation effect.
Made by Emily Hayman
December 31, 2016

Little slider built with flexbox. Somewhat responsive, and can have fixed elements alongside the slider area.
Made by Robert
November 28, 2016

HTML, CSS canvas slider.
Made by Nvagelis
October 29, 2016

HTML, CSS and JavaScript 3D smooth slider.
Made by Eduardo Allegrini
October 19, 2016

HTML and CSS cupcake slider with sprinkles!
Made by Jamie Coulter
October 14, 2016


Made by mario s maselli
October 12, 2016

Exploring UI animation #2 with HTML, CSS and JavaScript.
Made by mario s maselli
September 22, 2016

Exploring UI animation #3 with HTML, CSS and JavaScript.
Made by mario s maselli
September 22, 2016

Ecommerce Slider v2.0 with HTML, CSS and JavaScript.
Made by Pedro Castro
September 17, 2016

HTML, CSS and JavaScript clean slider with curved background.
Made by Ruslan Pivovarov
September 13, 2016

Exploring UI animation #1 with HTML, CSS and JavaScript.
Made by mario s maselli
September 8, 2016

Enjoy the power of CSS: Up & down each middle image and paginated slider with lightbox.
Made by Kseso
August 15, 2016

Double exposure is a photographic technique that combines 2 different images into a single image.
Made by Misaki Nakano
August 3, 2016

Slider using CSS3 property clip.
Made by Pedro Castro
May 1, 2016

Responsive CSS slider.
Made by geekwen
April 19, 2016

This is a simple slider experiment displaying words with beautiful meanings which cannot be directly translated. Focus: elegant typography and simple yet alluring transitions.
Made by Joe Harry
April 5, 2016

The animation idea is to change the value of CSS clip path, thus make a masking effect.
Made by Bhakti Al Akbar
March 31, 2016

Dot slider with HTML, CSS and JavaScript.
Made by Derek Nguyen
March 16, 2016

Prism effect slider with HTML, CSS and JavaScript.
Made by victor
March 12, 2016

Sliding background gallery with HTML, CSS and JavaScript.
Made by Ron Gierlach
November 30, 2015

HTML, CSS and JavaScript slider solution.
Made by Jürgen Genser
September 30, 2015

A product slider powered by Sequence.js. Sequence.js - The responsive CSS animation framework for creating unique sliders, presentations, banners, and other step-based applications.
Made by Ian Lunn
September 15, 2015

Tiny circle customized slider.
Made by Bram de Haan
August 11, 2015

Responsive GTA V slider with HTML, CSS and JavaScript.
Made by Eduard Mayer
January 24, 2014

It’s like a slider but it rotates cubeishly for reasons unknown.
Made by Eric Brewer
December 4, 2013

Made by Hugo DarbyBrown
August 28, 2013

Simple Sliders

Image overlay slider with HTML, CSS and vanilla JavaScript.
Made by Yugam
June 7, 2017

HTML and CSS featured image slider.
Made by Joshua Hibbert
June 16, 2016

Multi Axis Image Slider

Multi axis image slider with HTML, CSS and JavaScript.
Made by Burak Can
July 22, 2013

Cube slider, a small experiment with HTML5/CSS3 3d transforms.
Made by Ilya K.
June 26, 2013

Time does not stand still and with it progress. This also affected the Internet. You can already see how it’s changing appearance sites, is especially popular adaptive design. And in this regard, quite a few new ones have appeared adaptive jquery sliders , galleries, carousels or similar plugins.
1. Responsive Horizontal Posts Slider

Adaptive horizontal carousel with detailed instructions on installation. It is made in a simple style, but you can style it to suit yourself.

2. Slider on Glide.js

This slider is suitable for any website. It uses open source Glide.js. The slider colors can be easily changed.

3. Tilted Content Slideshow

Responsive content slider. The highlight of this slider is the 3D effect of the images, as well as different animations of random appearance.

4. Slider using HTML5 canvas

A very beautiful and impressive slider with interactive particles. It was made using HTML5 canvas,

5. Image Morphing Slider

Slider with a morphing effect (Smooth transformation from one object to another). IN in this example The slider is well suited for the portfolio of a web developer or web studio in the form of a portfolio.

6. Circular slider

Slider in the form of a circle with the effect of flipping the image.

7. Slider with blurred background

Adaptive slider with switching and background blur.

8. Responsive fashion slider

Simple, lightweight and responsive website slider.

9. Slicebox - jQuery 3D image slider(UPDATED)

Updated version of Slicebox slider with fixes and new features.

10.Free Animated Responsive Image Grid

JQuery plugin to create a flexible image grid that will switch shots using different animations and timings. This can look good as a background or decorative element on a website, as we can selectively appear new images and their transitions. The plugin comes in several versions.

11.Flex slider

A universal free plugin for your website. This plugin comes in several slider and carousel options.

12. Photo frame

Fotorama is a universal plugin. It has many settings, everything works quickly and easily, and you can view slides in full screen. The slider can be used both in a fixed size and adaptive, with or without thumbnails, with or without circular scrolling, and much more.

P.S.I installed the slider several times and I think that it is one of the best

13. Free and adaptive 3D slider gallery with thumbnails.

Experimental gallery slider 3DPanelLayout with a grid and interesting animation effects.

14. Slider on css3

The adaptive slider is made using css3 with smooth appearance of content and light animation.

15. WOW Slider

WOW Slider is an image slider with amazing visual effects.

17. Elastic

Elastic slider with full responsiveness and slide thumbnails.

18. Slit

This is a full screen responsive slider using css3 animation. The slider is made in two versions. The animation is done quite unusually and beautifully.

19. Adaptive photo gallery plus

Simple free slider-gallery with image loading.

20. Responsive Slider for WordPress

Adaptive free slider for WP.

21. Parallax Content Slider

Slider with parallax effect and control of each element using CSS3.

22. Slider with music link

Slider using JPlayer open source code. This slider resembles a presentation with music.

23. Slider with jmpress.js

The responsive slider is based on jmpress.js and will therefore allow you to add some interesting 3D effects to your slides.

24. Fast Hover Slideshow

Slide show with quick slide switching. Slides switch on hover.

25. Image Accordion with CSS3

Image accordion using css3.

26. A Touch Optimized Gallery Plugin

This is a responsive gallery that is optimized for touch devices.

27. 3D Gallery

3D Wall Gallery- created for the Safari browser, where the 3D effect will be visible. If you look at it on another browser, the functionality will be fine but the 3D effect will not be visible.

28. Slider with pagination

Responsive slider with pagination using JQuery UI slider. The idea is to use a simple navigation concept. It is possible to rewind all images or slide-by-slide switching.

29.Image Montage with jQuery

Automatically arrange images depending on screen width. A very useful thing when developing a portfolio website.

30. 3D Gallery

A simple 3D circular slider using css3 and jQuery.

31. Full screen mode with 3D effect using css3 and jQuery

A slider with the ability to view full-screen images with a beautiful transition.

Working on a book about jquery, I was faced with the fact that many of my subscribers asked me to tell in it how to write a slider script in jquery. Sorry, dear friends! This is the 21st century and, fortunately for us, all the delights of CSS3 are available to us, allowing us to implement such things without a single line javascript.

Part 1.

To begin with, I’ll explain to those who don’t know what a slider is. Slider- this is a block of a certain width that occupies part of a web page, or its entirety. Its main feature is that it changes automatically or manual mode content. The content can be: graphic images, and some text.

Of course, you may wonder: why reinvent the wheel if there are plenty of slider implementations in javascript? Here are my arguments:

  1. CSS effects are faster. This is clearly visible on mobile devices.
  2. To create a slider, no programming skills are required.

So, for our example, you need four images, although in your project you can make a strip with as many images as you need. The only condition is that all images must be the same size. Also, I forgot to tell you, our slider will be adaptive (yes, Adaptive layout , you read that right) and you can use it in any of your projects for any devices. But, enough chatter, I’m already itching to write mega-code. Let's start with HTML:

I left the alt attribute empty to save space, but you can fill it in yourself based on your SEO queries and to inform users who have disabled the display of images in their browser. I would also like to draw your attention to the fact that the first image ( alladin.jpg) will also be present at the end of the strip, which will allow our slider to scroll cyclically without jerking.

For convenience, width is 80% of the window, and max-width is the size of each individual photo (1000px in our example) since we don't want the image to be stretched:

Slider ( width: 80%; max-width: 1000px; )

In our CSS code, the width of the figure is expressed as a percentage of the div in which it is located. That is, if the image strip contains five photos and the div produces just one, the width of figure is increased by five times, which is 500% of the width of the container div:

The font-size: 0 setting sucks all the air out of the figure, removing any white space around and between images. position: relative allows you to easily move the figure during animation.

We need to equally divide the photos within the image strip. The formula is very simple: if we assume the figure's width is 100%, each image should take up 1/5 of the horizontal space:

There is a need to use the following CSS rules:

Imagestrip img (width: 20%; height: auto; )

Now let's change the overflow property for the div:

Slider ( width: 80%; max-width: 1000px; overflow: hidden )

Finally, we need to make the image strip move from left to right. If the container div's width is 100%, each movement of the image strip to the left will be measured as a percentage of that distance:

@keyframes slidy ( 20% ( left: 0%; ) 25% ( left: -100%; ) 45% ( left: -100%; ) 50% ( left: -200%; ) 70% ( left: -200 %; ) 75% ( left: -300%; ) 95% ( left: -300%; ) 100% ( left: -400%; ) )

Each image on the slider will be enclosed in a div and will move by 5%.

Slider figure ( position: relative; width: 500%; animation: 30s slidy infinite; font-size: 0; padding: 0; margin: 0; left: 0; )

Part 2.

We made it mega cool slider without javascript. Let's add control buttons to it before we rest on our laurels. More precisely, not into it (I’m already too lazy to tinker with it), but let’s create a new one.


So, our HTML code:

Now let's take care of animating our slides. Unfortunately, it will be different for different numbers of slides:

/* for a slider of two slides */ @keyframes slider__item-autoplay_count_2 ( 0%(opacity:0;) 20%(opacity:1;) 50%(opacity:1;) 70%(opacity:0;) 100%( opacity:0;) ) /* for a slider of three slides */ @keyframes slider__item-autoplay_count_3 ( 0%(opacity:0;) 10%(opacity:1;) 33% (opacity:1;) 43% (opacity: 0;) 100%(opacity:0;) ) /* for a four-slide slider */ @keyframes slider__item-autoplay_count_4 ( 0%(opacity:0;) 8% (opacity:1;) 25% (opacity:1; ) 33% (opacity:0;) 100%(opacity:0;) ) /* for a slider of five slides */ @keyframes slider__item-autoplay_count_5 ( 0%(opacity:0;) 7% (opacity:1;) 20 %(opacity:1;) 27% (opacity:0;) 100%(opacity:0;) )

Sad, isn't it? In addition, do not forget that for Opera, Chrome, IE, and Mozilla you need to write everything the same, but with the appropriate prefix. Now let’s write the code to animate our slides (hereinafter the code for three slides will be shown. You can see the code for more sites in the example code):

Slider_count_3 .item ( -moz-animation: slider__item-autoplay_count_3 15s infinite; -webkit-animation: slider__item-autoplay_count_3 15s infinite; -o-animation: slider__item-autoplay_count_3 15s infinite; animation: slider__item-autoplay_count_3 15s infinite; ) .item :nth -of-type(2) ( -moz-animation-delay:5s; -webkit-animation-delay:5s; -o-animation-delay:5s; animation-delay:5s; ) .item:nth-of-type (3) ( -moz-animation-delay:10s; -webkit-animation-delay:10s; -o-animation-delay:10s; animation-delay:10s; )

As you can see, for the first pair the zero offset does not change. In addition, the offset does not depend on the number of slides, so it can be described once for the maximum number of slides. Now let's make sure the slides don't change when the user hovers over our slider:

Slider:hover .item ( -moz-animation-play-state: paused; -webkit-animation-play-state: paused; -o-animation-play-state: paused; animation-play-state: paused; )

Finally, we got to switching our slides. As you know, there are a number of events that allow you to change the properties of an element when CSS help. For a mouse click, the pseudo-classes :focus, :target, or :checked on one of the page elements can help us. The pseudo-class :focus can only have one element per page, :target clogs the browser history and requires the presence of a tag; The pseudo-class:checked remembers the state before leaving the page, and, in the case of radio buttons, can only be selected on one element in the group. Let's take advantage of this. Insert before

the following HTML code

And then

:

/* Style of sliders in the "not selected" state */ .slider .item ~ .item ( opacity: 0.0; ) /* Style of sliders in the "selected" state */ .slider input:nth-of-type(1):checked ~ .item:nth-of-type(1), .slider input:nth-of-type(2):checked ~ .item:nth-of-type(2), .slider input:nth-of-type( 3):checked ~ .item:nth-of-type(3), .slider input:nth-of-type(4):checked ~ .item:nth-of-type(4), .slider input:nth- of-type(5):checked ~ .item:nth-of-type(5) ( opacity: 1.0; )

We used switching the opacity property of the container slide with the picture. This is due to the fact that, unlike the img element, you can place any additional information (for example, the title of the slide) in the div container. Of course, if we were using Javascript, we could use the data attribute. But we agreed, remember?)) For the slides we will indicate transition properties so that the switching occurs smoothly and not jerkily.

Slider .item ( -moz-transition: opacity 0.2s linear; -webkit-transition: opacity 0.2s linear; -o-transition: opacity 0.2s linear; transition: opacity 0.2s linear; )

Stopping the animation of all slides and buttons when selecting any slide can be done using the following CSS code:

Slider input:checked ~ .item ( opacity: 0.0; -moz-animation: none; -webkit-animation: none; -o-animation: none; animation: none; )

To support some older browsers, we do not animate the first slide, setting it to opacity: 1.0 , but we do have a problem: when the other two slides smoothly switch between each other, the first slide shines through. To eliminate this bug, set a transition-delay for all slides except the selected one, and for it we will make the z-index greater than that of all other slides:

Slider .item ( opacity: 1.0; -moz-transition: opacity 0.0s linear 0.2s; -webkit-transition: opacity 0.0s linear 0.2s; -o-transition: opacity 0.0s linear 0.2s; transition: opacity 0.0s linear 0.2s; ) .slider input:nth-of-type(1):checked ~ .item:nth-of-type(1), .slider input:nth-of-type(2):checked ~ .item:nth -of-type(2), .slider input:nth-of-type(3):checked ~ .item:nth-of-type(3), .slider input:nth-of-type(4):checked ~ .item:nth-of-type(4), .slider input:nth-of-type(5):checked ~ .item:nth-of-type(5) ( transition: opacity 0.2s linear; -moz-transition : opacity 0.2s linear; -webkit-transition: opacity 0.2s linear; -o-transition: opacity 0.2s linear; z-index: 6; )

To ensure that the slides do not conflict with other site elements (for example, they do not overlap a drop-down menu with a z-index less than or equal to 6), we create our own context for the block

by setting the minimum z-index required for visibility:

Slider ( position: relative; z-index: 0; )

That's all, actually. All that remains is to position our elements using the following CSS code and you can be happy:

Slider ( position: relative; z-index:0; ) .slider input ( display: none; ) .slider label ( bottom: 10px; display: inline-block; z-index: 2; width: 26px; height: 27px; background: #f4f4f5; border: 1px solid #e6e6e6; border-bottom-color: #bfbfbf; border-radius: 4px; box-shadow: inset 0 1px 0 #ffffff, 0 1px 2px #000000; text-align: center; cursor: pointer; font: 14px/27px arial, tahoma; color: #333; ) .slider .selector_list ( position: absolute; bottom: 15px; right: 15px; z-index: 11; ) .slider .item ( position: relative; width:100%; ) .slider .item ~ .item ( position: absolute; top: 0px; left: 0px; )

This is the kind of adaptive slider without Javascript using CSS3 you should end up with.