Card with toggle button

Card with toggle button

by Saksham Malhotra

HTML

<div class="card">
  <input type="checkbox" name="cbShow" id="cbShow">
  <label for="cbShow">+</label>
  <div class="content">Lorem ipsum dolor sit amet, consectetur adipisicing elit. Labore, numquam, quasi! Praesentium ad labore, autem in blanditiis, voluptatem laboriosam repellat quaerat hic ea illo sit nisi itaque commodi perferendis iste!</div>


</div>

SCSS

@mixin center($height, $width) {
  position: absolute;
  height: $height;
  width: $width;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
}

.card {
  @include center(300px, 200px);
  box-shadow: 0px 0px 5px 5px rgba(200, 200, 200, 0.2);
  background-image: linear-gradient(to bottom right, lighten(red, 10) 10%, lighten(red, 30) 100%);
  overflow: hidden;
  .content {
    padding: 10px;
    font-family: Arial;
    position: absolute;
    top: 0;
    left: 0;
    width: calc(100% - 20px);
    height: calc(100% - 80px);
    opacity: 0;
    color: #fff;
    /*transition:opacity 0.5s ease-out;*/
  }
  #cbShow {
    display: none;
    &:checked~.content {
      z-index: 3;
      opacity: 1;
      animation: ShowContent 0.3s;
    }
    &:checked~label {
      transform: rotate(405deg);
      box-shadow: 0px 0px 0px 300px lighten(#0072bc, 10);
    }
  }
  label {
    position: absolute;
    bottom: 5px;
    right: 5px;
    border-radius: 50%;
    background-color: lighten(#0072BC, 10);
    font-weight: bold;
    display: flex;
    align-items: center;
    justify-content: center;
    color: #FFF;
    height: 50px;
    width: 50px;
    font-size: 36px;
    cursor: pointer;
    z-index: 1;
    transform: rotate(0deg);
    box-shadow: 0px 0px 0px 0px lighten(#0072bc, 10);
    transition: transform 0.3s, box-shadow 0.3s;
  }
}

@keyframes ShowContent {
  0% {
    opacity: 0;
  }
  50% {
    opacity: 0;
  }
  100% {
    opacity: 1;
  }
}