JSFiddle - React, Tailwind, and code Playground
by PesecZ42
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-1531327431456-837da4b1d562?ixlib=rb-1.2.1&ixid=MnwxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8&auto=format&fit=crop&w=764&q=80');"
>
<h3>Castel Maggiore, Italy</h3>
</div>
<div
class="slide"
style="
background-image: url('https://images.unsplash.com/photo-1560744085-4b1a76def5ed?ixlib=rb-1.2.1&ixid=MnwxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8&auto=format&fit=crop&w=1470&q=80');
"
>
<h3>India</h3>
</div>
<div
class="slide"
style="
background-image: url('https://images.unsplash.com/photo-1570306296747-f7bb428e4fe0?ixlib=rb-1.2.1&ixid=MnwxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8&auto=format&fit=crop&w=880&q=80');
"
>
<h3>Denver, CO, USA</h3>
</div>
<div
class="slide.active"
style="
background-image: url('https://images.unsplash.com/photo-1580341289255-5b47c98a59dd?ixlib=rb-1.2.1&ixid=MnwxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8&auto=format&fit=crop&w=1470&q=80');
"
>
<h3>Jawa Barat, Indonesia</h3>
</div>
<div
class="slide"
style="
background-image: url('https://images.unsplash.com/photo-1552306062-29a5560e1c31?ixlib=rb-1.2.1&ixid=MnwxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8&auto=format&fit=crop&w=1470&q=80');
"
>
<h3>Valais, Switzerland</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:#2F4F4F;
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: #1111;
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;
}
.slade.active{
flex: 10;
}
.slade.active h3{
opacity:1 ;
transition: opasity 0.3s ease-in 0.4s;
}
JavaScript
const slides = document.querySelectorAll( '.slide')
for( const slide of slides ) {
slide.addeEventListener( 'click', ()=>{
clearActiveClasses()
slide.classList.add('active')
})
}
function clearActiveClasses(){
slides.forEach((slide)=>{
slide.classList.remove('active')
})
}