gouna Posted April 6, 2023 Share Posted April 6, 2023 Bonjour, Je suis en train de retravailler mes fiches produit, j'essaye de créer une sorte de carrousel pour afficher quelques blocs de texte. Voici le résultat, le changement de "slide" se fait en cliquant sur l'un des 3 petits boutons. Y a t-il un moyen de rendre le défilement automatique, et de le faire boucler ? Voici le code HTML utilisé : <div class="slider"> <input type="radio" name="slider" title="slide1" checked="checked" class="slider__nav"/> <input type="radio" name="slider" title="slide3" class="slider__nav"/> <div class="slider__inner"> <div class="slider__contents"> <p class="slider__caption">blabla</p> <p class="slider__txt">blabla</p> </div> <div class="slider__contents"> <p class="slider__caption">blabla</p> <p class="slider__txt">blabla</p> </div> </div> </div> Et le CSS utilisé : .slider { padding: 25px 0 0 0; border-radius: 0.5rem; height: 100%; position: relative; overflow: hidden; display: -webkit-box; display: -webkit-flex; display: -ms-flexbox; display: flex; -webkit-flex-flow: row nowrap; -ms-flex-flow: row nowrap; flex-flow: row nowrap; -webkit-box-align: end; -webkit-align-items: flex-end; -ms-flex-align: end; align-items: flex-end; -webkit-box-pack: center; -webkit-justify-content: center; -ms-flex-pack: center; justify-content: center; } .slider__nav { width: 12px; height: 12px; margin: 45px 10px 10px 10px; border-radius: 50%; z-index: 10; outline: 6px solid #ccc; outline-offset: -6px; box-shadow: 0 0 0 0 #333, 0 0 0 0 rgba(51, 51, 51, 0); cursor: pointer; -webkit-appearance: none; -moz-appearance: none; appearance: none; -webkit-backface-visibility: hidden; backface-visibility: hidden; } .slider__nav:checked { -webkit-animation: check 0.4s linear forwards; animation: check 0.4s linear forwards; } .slider__nav:checked:nth-of-type(1) ~ .slider__inner { left: 0%; } .slider__nav:checked:nth-of-type(2) ~ .slider__inner { left: -100%; } .slider__nav:checked:nth-of-type(3) ~ .slider__inner { left: -200%; } .slider__nav:checked:nth-of-type(4) ~ .slider__inner { left: -300%; } .slider__inner { background: #f0eeef; position: absolute; top: 0; left: 0; width: 300%; height: 100%; -webkit-transition: left 0.4s; transition: left 0.4s; display: -webkit-box; display: -webkit-flex; display: -ms-flexbox; display: flex; -webkit-flex-flow: row nowrap; -ms-flex-flow: row nowrap; flex-flow: row nowrap; } .slider__contents { height: 100%; padding: 2rem; text-align: center; display: -webkit-box; display: -webkit-flex; display: -ms-flexbox; display: flex; -webkit-box-flex: 1; -webkit-flex: 1; -ms-flex: 1; flex: 1; -webkit-flex-flow: column nowrap; -ms-flex-flow: column nowrap; flex-flow: column nowrap; -webkit-box-align: center; -webkit-align-items: center; -ms-flex-align: center; align-items: center; -webkit-box-pack: center; -webkit-justify-content: center; -ms-flex-pack: center; justify-content: center; } Merci ! Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now