●▲■ 개발일기

[CSS]버튼 클릭하면 박스가 나타나면서 아래 박스 부드럽게 밀어내리는 애니메이션 CSS 본문

👉 css.scss.sass/css

[CSS]버튼 클릭하면 박스가 나타나면서 아래 박스 부드럽게 밀어내리는 애니메이션 CSS

●▲■ PRINT 2022. 4. 29. 15:57
<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
  <style>
    body {
      display: flex;
      align-items: center;
      justify-content: center;
      flex-direction: column;
    }
    nav {
      padding: 3rem;
      background-color: #e1e1e1;
      width: 100%;
      text-align: center;
    }
    .box1 {
      display: flex;
      align-items: center;
      justify-content: center;
      width: 20rem;
      height: 5rem;
      background-color: #ff0000;
      color: #fff;
      margin: 1rem;
    }

    .box2 {
      display: flex;
      align-items: center;
      justify-content: center;
      width: 20rem;
      background-color: #ffaa00;
      color: #fff;
      margin: 1rem;
      visibility: hidden;
      height: 0vh;
      opacity: 0;
      transition: all .5s;
      flex-direction: column;
    }
    .box2 .text-box {
      display: block;
      position: relative;
      text-align: center;
      padding: 1rem;
      font-size: 1rem;
    }
    .on {
      visibility: visible;
      height: fit-content;
      opacity: 1;
      padding: 2rem 0;
    }
    .box3 {
      display: flex;
      align-items: center;
      justify-content: center;
      width: 20rem;
      height: 5rem;
      background-color: #709900;
      color: #fff;
      margin: 1rem;
    }
    button {
      display: flex;
      align-items: center;
      justify-content: center;
      padding: 1rem;
      width: 80%;
      margin: 2rem;
      background-color: #006bae;
      border-radius: .5rem;
      color: #fff;
    }
  </style>
</head>

<body>
  <!-- <div class="box3">
    box3
  </div> -->
  <nav>
    버튼 클릭하면 박스가 나타나면서 아래 박스 부드럽게 밀어내리는 애니메이션 CSS
  </nav>
  <div class="box2">
    box2
    <div class="text-box">
      Lorem ipsum 
    </div>
  </div>
  <div class="box1">
    box1
  </div>
  <button onclick="document.querySelector('.box2').classList.toggle('on')">box2 Show!</button>
</body>

</html>

 

See the Pen Untitled by Lee sangmin (@sangmin2) on CodePen.