<div class="slider">
<input type="radio" name="toggle" id="btn-1" checked>
<input type="radio" name="toggle" id="btn-2">
<input type="radio" name="toggle" id="btn-3">
<div class="slider-controls">
<label for="btn-1"></label>
<label for="btn-2"></label>
<label for="btn-3"></label>
</div>
<ul class="slides">
<li class="slide">
<div class="slide-content">
<h2 class="slide-title">Slide #1</h2>
<p class="slide-text">Lorem ipsum dolor sit amet consectetur adipisicing elit. Quaerat dignissimos commodi eos totam perferendis possimus dolorem, deleniti vitae harum? Enim.</p>
<a href="#" class="slide-link">Learn more</a>
</div>
<p class="slide-image">
<img src="https://placeimg.com/320/240/tech" alt="stuff" width="320" height="240">
</p>
</li>
<li class="slide">
<div class="slide-content">
<h2 class="slide-title">Slide #2</h2>
<p class="slide-text">Nisi ratione magni ea quis animi incidunt velit voluptate dolorem enim possimus, nam provident excepturi ipsam nihil molestiae minus delectus!</p>
<a href="#" class="slide-link">Amazing deal</a>
</div>
<p class="slide-image">
<img src="https://placeimg.com/320/240/animals" alt="stuff" width="320" height="240">
</p>
</li>
<li class="slide">
<div class="slide-content">
<h2 class="slide-title">Slide #3</h2>
<p class="slide-text">Quisquam quod ut quasi, vero obcaecati laudantium asperiores corporis ad atque. Expedita fugit dicta maxime vel doloribus sequi, facilis dignissimos.</p>
<a href="#" class="slide-link">Get started</a>
</div>
<p class="slide-image">
<img src="https://placeimg.com/320/240/any" alt="stuff" width="320" height="240">
</p>
</li>
</ul>
</div>
html {
box-sizing: border-box;
}
*,
*::before,
*::after {
box-sizing: inherit;
padding: 0;
margin: 0;
}
body {
font-size: 16px;
line-height: 1.5;
font-family: Roboto, sans-serif;
}
.slider {
position: relative;
width: 960px;
height: 300px;
margin: 50px auto;
box-shadow: 0 2px 2px 0 rgba(0, 0, 0, 0.14), 0 1px 5px 0 rgba(0, 0, 0, 0.12),
0 3px 1px -2px rgba(0, 0, 0, 0.2);
overflow: hidden;
}
.slider-controls {
position: absolute;
bottom: 0px;
left: 50%;
width: 200px;
text-align: center;
transform: translatex(-50%);
z-index: 1000;
list-style: none;
text-align: center;
}
.slider input[type="radio"] {
position: absolute;
top: 0;
left: 0;
opacity: 0;
width: 0;
height: 0;
}
.slider-controls label {
display: inline-block;
border: none;
height: 20px;
width: 20px;
border-radius: 50%;
cursor: pointer;
background-color: #212121;
transition: background-color 0.2s linear;
}
#btn-1:checked ~ .slider-controls label[for="btn-1"] {
background-color: #ff4081;
}
#btn-2:checked ~ .slider-controls label[for="btn-2"] {
background-color: #ff4081;
}
#btn-3:checked ~ .slider-controls label[for="btn-3"] {
background-color: #ff4081;
}
/* SLIDES */
.slides {
list-style: none;
padding: 0;
margin: 0;
height: 100%;
}
.slide {
position: absolute;
top: 0;
left: 0;
display: flex;
justify-content: space-between;
padding: 20px;
width: 100%;
height: 100%;
opacity: 0;
transform: translatex(-100%);
transition: transform 250ms linear;
}
.slide-content {
width: 400px;
}
.slide-title {
margin-bottom: 20px;
font-size: 36px;
}
.slide-text {
margin-bottom: 20px;
}
.slide-link {
display: inline-block;
padding: 10px 20px;
color: #fff;
border-radius: 3px;
text-decoration: none;
background-color: #ff4081;
}
.slide-image img {
max-width: 100%;
}
/* Slide animations */
#btn-1:checked ~ .slides .slide:nth-child(1) {
transform: translatex(0);
opacity: 1;
}
#btn-2:checked ~ .slides .slide:nth-child(2) {
transform: translatex(0);
opacity: 1;
}
#btn-3:checked ~ .slides .slide:nth-child(3) {
transform: translatex(0);
opacity: 1;
}
#btn-1:not(:checked) ~ .slides .slide:nth-child(1) {
animation-name: swap-out;
animation-duration: 300ms;
animation-timing-function: linear;
}
#btn-2:not(:checked) ~ .slides .slide:nth-child(2) {
animation-name: swap-out;
animation-duration: 300ms;
animation-timing-function: linear;
}
#btn-3:not(:checked) ~ .slides .slide:nth-child(3) {
animation-name: swap-out;
animation-duration: 300ms;
animation-timing-function: linear;
}
@keyframes swap-out {
0% {
transform: translatex(0);
opacity: 1;
}
50% {
transform: translatex(50%);
opacity: 0;
}
100% {
transform: translatex(100%);
}
}
This Pen doesn't use any external CSS resources.
This Pen doesn't use any external JavaScript resources.