CSS close X icon

CSS only close X button using one <a>

by Allen N.

HTML

<div class="modal-dialog-popup">
  <a href="#" class="close" tabindex="0" role="button">close</a>
</div>
<div class="modal-dialog-popup">
  <a href="#" class="close" tabindex="0" role="button">close</a>
</div>

SCSS

$bg-color: #1F2227;
$font-color: #F0F0F0;
$close-color-hover: #77FF77;

html, 
body {
  position: relative;
  width: 100%;
  min-width: 0;
  margin: 0;
  padding: 0;
  height: 100%;
  color: $font-color;
  background: $bg-color;
  font-family: Helvetica, Arial;
}

.modal-dialog-popup {
  position: absolute;
  top: 50%;
  left: 50%;
  width: 90%;
  max-width: 555px;
  height: 80%;
  max-height: 333px;
  background-color: rgba(#111111, 0.9);
  border: 1px solid #555555;
  border-radius: 5px;
  transform: translate(-50%, -50%);
}

.close {
    position: absolute;
    top: 0;
    right: 0;
    display: block;
    width: 50px;
    height: 50px;
    font-size: 0;
}
.close:before, 
.close:after {
    position: absolute;
    top: 50%;
    left: 50%;
    width: 5px;
    height: 20px;
    background-color: $font-color;
    transform: rotate(45deg) translate(-50%, -50%);
    transform-origin: top left;
    transition: all 420ms;
    content: '';
}
.close:after {
    transform: rotate(-45deg) translate(-50%, -50%);
}
.close:hover:before, 
.close:hover:after {
    background-color: $close-color-hover;
}





.modal-dialog-popup:first-of-type {
  margin: -22px 0 0 -11px;
  
  .close:before, 
  .close:after {
    width: 2px;
  }
}
.modal-dialog-popup:first-of-type + .modal-dialog-popup {
  margin: 22px 0 0 11px;
}