JSFiddle - React, Tailwind, and code Playground
by Tolibjon Tolibov
HTML
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<link rel="stylesheet" href="styles.css" />
<title>Карточки | Проект 1</title>
</head>
<body>
<div class="container">
<div
class="slide"
style="background-image: url('https://images.unsplash.com/photo-1485965120184-e220f721d03e?ixlib=rb-1.2.1&ixid=MnwxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8&auto=format&fit=crop&w=800&q=80');"
>
<h3>Peugeot</h3>
</div>
<div
class="slide"
style="
background-image: url('https://images.unsplash.com/photo-1532298229144-0ec0c57515c7?ixid=MnwxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8&ixlib=rb-1.2.1&auto=format&fit=crop&w=1400&q=80');
"
>
<h3>Aarhus</h3>
</div>
<div
class="slide"
style="
background-image: url('https://images.unsplash.com/photo-1557616907-6bea6f8991d1?ixlib=rb-1.2.1&ixid=MnwxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8&auto=format&fit=crop&w=1400&q=80');
"
>
<h3>Langstek</h3>
</div>
<div
class="slide active"
style="
background-image: url('https://images.unsplash.com/photo-1576435728678-68d0fbf94e91?ixid=MnwxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8&ixlib=rb-1.2.1&auto=format&fit=crop&w=1400&q=80');
"
>
<h3>Open</h3>
</div>
<div
class="slide"
style="
background-image: url('https://images.unsplash.com/photo-1561642445-b789b9a7e6f0?ixid=MnwxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8&ixlib=rb-1.2.1&auto=format&fit=crop&w=1400&q=80');
"
>
<h3>Pearson</h3>
</div>
</div>
<script src="app.js"></script>
</body>
</html>
CSS
@import url('https://fonts.googleapis.com/css?family=Muli&display=swap');
* {
box-sizing: border-box;
}
body {
font-family: 'Muli', sans-serif;
overflow: hidden;
margin: 0;
background-color: rgb(44, 18, 0);
height: 100vh;
display: flex;
justify-content: center;
align-items: center;
}
.container{
width: 100%;
display: flex;
padding: 0 20px;
}
.slide {
height: 80vh;
border-radius: 20px;
margin: 10px;
cursor: pointer;
color: #fff;
flex: 1;
background-size: cover;
background-position: center;
background-repeat: no-repeat;
position: relative;
transition: all 500ms ease-in-out;
}
.slide h3 {
position: absolute;
font-size: 24px;
bottom: 20px;
left: 20px;
margin: 0;
opacity: 0;
}
.slide.active {
flex:10;
}
.slide.active h3{
opacity: 1;
transition: opacity 0.3s ease-in 0.4s;
}
JavaScript
const slides = document.querySelectorAll('.slide');
slides.forEach(slide => slide.addEventListener('click', () => {
clearActiveClasses();
slide.classList.add('active')
}))
function clearActiveClasses(){
slides.forEach(slide =>
slide.classList.remove('active')
)
}