DEV Community

Cover image for How to make Slider(Carousel)
Rahul Raidas
Rahul Raidas

Posted on

How to make Slider(Carousel)

AS a frontEnd developer, here is the step by step code ,how to code carousel(slider).
step1.(HTML)
Alt Text

step1.(css)
Alt Text

step 2.(HTML)
inside carousel
Alt Text

step 2.(css)
Alt Text

in a section class we use flex basis property. because of this each section item spaces equally to each other;
Alt Text

in web browser shows like that
Alt Text

in slider class slider has a six childrens. and each equally spaces 100% so total slider width is (100* multiply by number of slider childrens).beacuse of this, each section has full width.
.slider{
width:600%;
}
Alt Text
after this ,in web browser
Alt Text

now align the each section item center
Alt Text
in section tag ,you can add background images, other things also

add buttons
Alt Text
css for button:
Alt Text

Alt Text
for smooth sliding : add transition property in slider class
and horizontal slide none , to add overflow:hidden property in carousel class.
add javaScript:

Alt Text

Alt Text

result:

Alt Text

Top comments (5)

Collapse
 
Sloan, the sloth mascot
Comment deleted
Collapse
 
rahulra08598872 profile image
Rahul Raidas

I use brackets ide with light theme

Collapse
 
tfantina profile image
Travis Fantina

Hey @rahulra08598872 great post, you may want to use code blocks rather than images for the code.

Collapse
 
rahulra08598872 profile image
Rahul Raidas

OK, I am using first time.

Collapse
 
tfantina profile image
Travis Fantina

No worries just wanted to point it out for future reference. Good article.