Last active
October 5, 2016 14:40
-
-
Save jh3y/1f6029449ccaf1993e7ceba991772119 to your computer and use it in GitHub Desktop.
Pure CSS carousel exploration
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
.carousel { | |
height: 300px; | |
width: 400px; | |
overflow: hidden; | |
text-align: center; | |
position: relative; | |
padding: 0; | |
list-style: none; | |
} | |
.carousel__controls, | |
.carousel__activator { | |
display: none; | |
} | |
.carousel__activator:nth-of-type(5):checked ~ .carousel__track { | |
transform: translateX(-400%); | |
} | |
.carousel__activator:nth-of-type(5):checked ~ .carousel__slide:nth-of-type(5) { | |
animation: carousel-show-slide 0.5s; | |
top: 0; | |
left: 0; | |
right: 0; | |
} | |
.carousel__activator:nth-of-type(5):checked ~ .carousel__controls:nth-of-type(5) { | |
display: block; | |
} | |
.carousel__activator:nth-of-type(5):checked ~ .carousel__indicators .carousel__indicator:nth-of-type(5) { | |
opacity: 1; | |
} | |
.carousel__activator:nth-of-type(4):checked ~ .carousel__track { | |
transform: translateX(-300%); | |
} | |
.carousel__activator:nth-of-type(4):checked ~ .carousel__slide:nth-of-type(4) { | |
animation: carousel-show-slide 0.5s; | |
top: 0; | |
left: 0; | |
right: 0; | |
} | |
.carousel__activator:nth-of-type(4):checked ~ .carousel__controls:nth-of-type(4) { | |
display: block; | |
} | |
.carousel__activator:nth-of-type(4):checked ~ .carousel__indicators .carousel__indicator:nth-of-type(4) { | |
opacity: 1; | |
} | |
.carousel__activator:nth-of-type(3):checked ~ .carousel__track { | |
transform: translateX(-200%); | |
} | |
.carousel__activator:nth-of-type(3):checked ~ .carousel__slide:nth-of-type(3) { | |
animation: carousel-show-slide 0.5s; | |
top: 0; | |
left: 0; | |
right: 0; | |
} | |
.carousel__activator:nth-of-type(3):checked ~ .carousel__controls:nth-of-type(3) { | |
display: block; | |
} | |
.carousel__activator:nth-of-type(3):checked ~ .carousel__indicators .carousel__indicator:nth-of-type(3) { | |
opacity: 1; | |
} | |
.carousel__activator:nth-of-type(2):checked ~ .carousel__track { | |
transform: translateX(-100%); | |
} | |
.carousel__activator:nth-of-type(2):checked ~ .carousel__slide:nth-of-type(2) { | |
animation: carousel-show-slide 0.5s; | |
top: 0; | |
left: 0; | |
right: 0; | |
} | |
.carousel__activator:nth-of-type(2):checked ~ .carousel__controls:nth-of-type(2) { | |
display: block; | |
} | |
.carousel__activator:nth-of-type(2):checked ~ .carousel__indicators .carousel__indicator:nth-of-type(2) { | |
opacity: 1; | |
} | |
.carousel__activator:nth-of-type(1):checked ~ .carousel__track { | |
transform: translateX(0%); | |
} | |
.carousel__activator:nth-of-type(1):checked ~ .carousel__slide:nth-of-type(1) { | |
animation: carousel-show-slide 0.5s; | |
top: 0; | |
left: 0; | |
right: 0; | |
} | |
.carousel__activator:nth-of-type(1):checked ~ .carousel__controls:nth-of-type(1) { | |
display: block; | |
} | |
.carousel__activator:nth-of-type(1):checked ~ .carousel__indicators .carousel__indicator:nth-of-type(1) { | |
opacity: 1; | |
} | |
.carousel__control { | |
height: 30px; | |
width: 30px; | |
margin-top: -15px; | |
top: 50%; | |
position: absolute; | |
display: block; | |
cursor: pointer; | |
border-width: 5px 5px 0 0; | |
border-style: solid; | |
border-color: #fafafa; | |
opacity: 0.35; | |
outline: 0; | |
z-index: 3; | |
} | |
.carousel__control:hover { | |
opacity: 1; | |
} | |
.carousel__control--forward { | |
left: 10px; | |
transform: rotate(-135deg); | |
} | |
.carousel__control--backward { | |
right: 10px; | |
transform: rotate(45deg); | |
} | |
.carousel__indicators { | |
position: absolute; | |
bottom: 20px; | |
width: 100%; | |
text-align: center; | |
} | |
.carousel__indicator { | |
height: 15px; | |
width: 15px; | |
border-radius: 100%; | |
display: inline-block; | |
z-index: 2; | |
cursor: pointer; | |
opacity: 0.35; | |
margin: 0 2.5px 0 2.5px; | |
} | |
.carousel__indicator:hover { | |
opacity: 0.75; | |
} | |
.carousel__track { | |
position: absolute; | |
top: 0; | |
right: 0; | |
bottom: 0; | |
left: 0; | |
padding: 0; | |
margin: 0; | |
transition: transform 0.5s ease 0s; | |
} | |
.carousel__track .carousel__slide { | |
display: block; | |
top: 0; | |
left: 0; | |
right: 0; | |
} | |
.carousel__track .carousel__slide:nth-of-type(1) { | |
transform: translateX(0%); | |
} | |
.carousel__track .carousel__slide:nth-of-type(2) { | |
transform: translateX(100%); | |
} | |
.carousel__track .carousel__slide:nth-of-type(3) { | |
transform: translateX(200%); | |
} | |
.carousel__track .carousel__slide:nth-of-type(4) { | |
transform: translateX(300%); | |
} | |
.carousel__track .carousel__slide:nth-of-type(5) { | |
transform: translateX(400%); | |
} | |
.carousel__slide { | |
height: 100%; | |
position: absolute; | |
overflow-y: auto; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<ul class="carousel my-carousel"> | |
<input class="carousel__activator" type="radio" id="1" name="activator" checked="checked"/> | |
<input class="carousel__activator" type="radio" id="2" name="activator"/> | |
<input class="carousel__activator" type="radio" id="3" name="activator"/> | |
<div class="carousel__controls"> | |
<label class="carousel__control carousel__control--backward" for="2"></label> | |
<label class="carousel__control carousel__control--forward" for="3"></label> | |
</div> | |
<div class="carousel__controls"> | |
<label class="carousel__control carousel__control--backward" for="3"></label> | |
<label class="carousel__control carousel__control--forward" for="1"></label> | |
</div> | |
<div class="carousel__controls"> | |
<label class="carousel__control carousel__control--backward" for="1"></label> | |
<label class="carousel__control carousel__control--forward" for="2"></label> | |
</div> | |
<li class="carousel__slide"> | |
<h1>1</h1> | |
</li> | |
<li class="carousel__slide"> | |
<h1>2</h1> | |
</li> | |
<li class="carousel__slide"> | |
<h1>3</h1> | |
</li> | |
<div class="carousel__indicators"> | |
<label class="carousel__indicator" for="1"></label> | |
<label class="carousel__indicator" for="2"></label> | |
<label class="carousel__indicator" for="3"></label> | |
</div> | |
</ul> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment