Categories
Web development

Pure CSS Envelope (Open/Close on click)

Pure CSS Envelope (Open/Close on click)

To learn how to create the CSS Envelope (Open/Close on click) follow the steps below and watch the video tutorial:

Demo:

*to see the CSS Envelope (Open/Close on click) on the website click here.

Step1.

Add HTML

<div class="envelope-container">
  <input id="flap" type="checkbox">
  <label class="flap" for="flap"></label>
  <div class="envelope-back"></div>
  <div class="card">Thanks!</div>
  <div class="card-front"></div> 
</div>

Step2.

Add CSS

Set the colour and the position of the background and elements:

body {
  height: 100vh;
  display: flex;
  justify-content: center;
  align-items: center;
  background-color: #e9f5db;
}
.envelope-container {
  position: relative;
}

Style the envelope and the card:

input#flap {
  display: none;
}
.envelope-back {
  position: relative;
  width: 320px;
  height: 200px;
  background-color: #718355;
}

.envelope-back:before {
  content:"";
  position: absolute;
  background-color: rgba(0,0,0,0.07);
  width: 320px;
  height:10px;
  border-radius:50%;
  top:220px;
}

.card {
  position: absolute;
  width:300px;
  height: 180px;
  background-color: white;
  top:10px;
  left:10px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size:40px;
  font-family: Brush Script MT;
  transition: .1s;
  z-index:1;
  cursor: pointer;
}

.card-front {
  position: absolute;
  width:0;
  height:0;
  border-bottom: 100px solid #87986a;
  border-left: 160px solid transparent;
  border-right: 160px solid transparent;
  top:100px;
  left:0;
  z-index:3;
}

.card-front:before, .card-front:after {
  content:"";
  position: absolute;
  border-bottom: 100px solid transparent;
  border-top: 100px solid transparent;
  height:0;
  width:0;
}

.card-front:before {
  border-left: 161px solid transparent;
  border-right: 161px solid #97a97c;
  top:-100px;
  left:-162px;
}

.card-front:after {
  border-right: 161px solid transparent;
  border-left: 161px solid #97a97c;
  top:-100px;
  left:-160px;
}

.flap {
  position: absolute;
  width:0;
  height:0;
  border-top: 110px solid #b5c99a;
  border-left: 160px solid transparent;
  border-right: 160px solid transparent;
  top:0;
  left:0;
  cursor: pointer;
  transition: .3s;
  transform-origin: top;
  z-index:4;
}
CSS Envelope

Open and close an envelope:

#flap:checked + .flap {
  transform: rotateX(180deg);
}

#flap:checked ~ .card-front {
  z-index:7;
}

#flap:checked ~ .card {
  z-index:4;
  transform: translateY(-60px);
}

Watch also the video tutorial:

Enjoy coding!

Read also:

CSS Envelope (Open/Close on Hover)

CSS Valentine’s Day Card

CSS 3d flip Business Card