JSFiddle - React, Tailwind, and code Playground

by zaurmag

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-1591824438708-ce405f36ba3d?ixid=MnwxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8&ixlib=rb-1.2.1&auto=format&fit=crop&w=2134&q=80');"
  >
    <h3>Tiger on the road</h3>
  </div>
  <div
      class="slide"
      style="
          background-image: url('https://images.unsplash.com/photo-1529778873920-4da4926a72c2?ixid=MnwxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8&ixlib=rb-1.2.1&auto=format&fit=crop&w=676&q=80');
        "
  >
    <h3>Little cat</h3>
  </div>
  <div
      class="slide"
      style="
          background-image: url('https://images.unsplash.com/photo-1527161153332-99adcc6f2966?ixid=MnwxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8&ixlib=rb-1.2.1&auto=format&fit=crop&w=1049&q=80');
        "
  >
    <h3>Elephants</h3>
  </div>
  <div
      class="slide"
      style="
          background-image: url('https://images.unsplash.com/photo-1574870111867-089730e5a72b?ixid=MnwxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8&ixlib=rb-1.2.1&auto=format&fit=crop&w=634&q=80');
        "
  >
    <h3>Giraffe</h3>
  </div>
  <div
      class="slide"
      style="
          background-image: url('https://images.unsplash.com/photo-1456926631375-92c8ce872def?ixid=MnwxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8&ixlib=rb-1.2.1&auto=format&fit=crop&w=1050&q=80');
        "
  >
    <h3>Peeking leopard</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 {
  background: #fff url("https://images.unsplash.com/photo-1569982175971-d92b01cf8694?ixid=MnwxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8&ixlib=rb-1.2.1&auto=format&fit=crop&w=675&q=80") 50% 50% / cover no-repeat;
  font-family: 'Muli', sans-serif;
  overflow: hidden;
  margin: 0;
  padding: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  height: 100vh;
}
.container {
  width: 100%;
  padding: 30px 20px;
  display: flex;
}
.slide {
  border-radius: 20px;
  background-size: cover;
  background-position: 50% 50%;
  background-repeat: no-repeat;
  cursor: pointer;
  flex: 1;
  position: relative;
  transition: flex .5s ease-in-out;
  height: 80vh;
  margin: 10px;
}
.slide h3 {
  color: #fff;
  font-size: 24px;
  position: absolute;
  bottom: 30px;
  margin: 0;
  left: 50%;
  transform: translate(-50%);
  white-space: nowrap;
  opacity: 0;
  transition: opacity .3s ease;
}
/**
 * Active state
 */
.slide.is-active {
  flex: 5;
  transition: flex .5s ease-in-out;
}
.slide.is-active h3 {
  opacity: 1;
  transition: opacity .3s ease .4s;
}

JavaScript

const slides = document.querySelectorAll('.slide')

for (const slide of slides) {
  slide.addEventListener('click', () => {
    clearActiveClasses()

    slide.classList.add('is-active')
  })
}

function clearActiveClasses () {
  slides.forEach(slide => {
    slide.classList.remove('is-active')
  })
}