JSFiddle - React, Tailwind, and code Playground

by annndrewww

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-1613662265610-051b02ce6630?ixid=MnwxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8&ixlib=rb-1.2.1&auto=format&fit=crop&w=750&q=80');"
  >
    <h3>Geography</h3>
  </div>
  <div
      class="slide"
      style="
          background-image: url('https://images.unsplash.com/photo-1596495577886-d920f1fb7238?ixid=MnwxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8&ixlib=rb-1.2.1&auto=format&fit=crop&w=754&q=80');
        "
  >
    <h3>Math</h3>
  </div>
  <div
      class="slide"
      style="
          background-image: url('https://images.unsplash.com/photo-1509869175650-a1d97972541a?ixid=MnwxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8&ixlib=rb-1.2.1&auto=format&fit=crop&w=750&q=80');
        "
  >
    <h3>Physic</h3>
  </div>
  <div
      class="slide active"
      style="
          background-image: url('https://images.unsplash.com/photo-1603126857599-f6e157fa2fe6?ixid=MnwxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8&ixlib=rb-1.2.1&auto=format&fit=crop&w=750&q=80');
        "
  >
    <h3>Chemistry</h3>
  </div>
  <div
      class="slide "
      style="
          background-image: url('https://images.unsplash.com/photo-1567427018141-0584cfcbf1b8?ixid=MnwxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8&ixlib=rb-1.2.1&auto=format&fit=crop&w=750&q=80');
        "
  >
    <h3>Biology</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: url('https://images.unsplash.com/photo-1542621334-a254cf47733d?ixid=MnwxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8&ixlib=rb-1.2.1&auto=format&fit=crop&w=750&q=80');
  background-position: center;
  background-repeat: no-repeat;
  background-size: cover;
  height: 100vh;
  display: flex;
  justify-content: center;
  align-items: center;
}

.container {
  width: 100%;
  display: flex;
  padding: 0 20px;
}

.slide {
  position: relative;
  height: 80vh;
  border-radius: 20px;
  margin: 10px;
  cursor: pointer;
  color: #000;
  flex: 1;
  background-size: cover;
  background-position: center;
  background-repeat: no-repeat;
  transition: all 500ms ease-in-out;
}

.slide h3 {
  position: absolute;
  bottom: 20px;
  left: 10px;
  margin: 0;
  font-size: 24px;
  color: #fff; 
  opacity: 0;
}

.slide.active {
  flex: 7;
}

.slide.active h3 {
  opacity: 1;
  transition: opacity .3s ease-in 0.4;
}

JavaScript

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

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


        slide.classList.add('active');
    })

}

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