<div class="title-container">
  <h1 class="title">It's all about context.</h1>
  <h1 class="title-down">Ajax'ing something...</h1>
</div>

<fieldset class="field-container">
  <input type="text" placeholder="Search..." class="field" />
  <div class="icons-container">
    <div class="icon-search"></div>
    <div class="icon-close">
      <div class="x-up"></div>
      <div class="x-down"></div>
    </div>
  </div>
</fieldset>
@import url(https://fonts.googleapis.com/css?family=Montserrat);

$hint: #FAF8F8;
$turqoise: #17EAD9;
$cornflower-blue: #6078EA;
$tundora: #4B4848;
$electric-violet: #7C26F8;
$snappy:  cubic-bezier(0.694,  0.048, 0.335, 1.000);

@keyframes spin {
  0% {
    transform: rotate(0deg);
  }
  100% {
    transform: rotate(360deg);
  }
}

@keyframes color-1 {
  0% {
    background-color: #EB73B9;
  }
  100% {
    background-color: #17EAD9;
  }
}

::selection {
  background: $cornflower-blue;
  color: white;
  text-shadow: none;
}

::-webkit-selection{
  background: $cornflower-blue;
  color: white;
  text-shadow: none;
}

body {
  font-family: 'Montserrat', 'Helevtica', sans-serif;
  position: relative;
  width: 100%;
  height: 100vh;
  background-color: darken($hint, 4%);
  color: $tundora;
  display: flex;
  justify-content: center;
  align-items: center;
  transition: background-color 1.25s ease-in-out;
  &.is-focus {
    background-color: $turqoise;
  }
}

.title-container {
  position: absolute;
  top: 38%;
  left: 50%;
  width: 80%;
  margin: 0 auto;
  text-align: center;
  overflow: hidden;
  transform: translate(-50%, -50%);
  .title {
    transform: translateY(-100%);
    transition: transform 0.3s ease;
    transition-delay: 0.25s;
    margin: 0;
    color: $cornflower-blue;
  }
  .title-down {
    transform: translateY(100%);
    transition: transform 0.3s ease;
    transition-delay: 0.25s;
    margin: 0;
    color: $cornflower-blue;
  }
  .is-focus & {
    .title {
      transform: translateY(0);
    }
  }
  .is-type & {
    .title-down {
      transform: translateY(-30px);
    }
    .title {
      transform: translateY(-100%);
    }
  }
}

.field-container {
  position: relative;
  padding: 0;
  margin: 0;
  border: 0;
  width: 330px;
  height: 40px;
}

.icons-container {
  position: absolute;
  top: 11px;
  right: -25px;
  width: 35px;
  height: 35px;
  overflow: hidden;
}

.icon-close {
  position: absolute;
  top: 2px;
  left: 2px;
  width: 75%;
  height: 75%;
  opacity: 0;
  cursor: pointer;
  transform: translateX(-200%);
  border-radius: 50%;
  transition: opacity 0.25s ease, transform 0.43s $snappy;
  &:before {
    content: "";
    border-radius: 50%;
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    opacity: 0;
    border: 2px solid transparent;
    border-top-color: $cornflower-blue;
    border-left-color: $cornflower-blue;
    border-bottom-color: $cornflower-blue;
    transition: opacity 0.2s ease;
  }
  .x-up {
    position: relative;
    width: 100%;
    height: 50%;
    &:before {
      content: "";
      position: absolute;
      bottom: 2px;
      left: 3px;
      width: 50%;
      height: 2px;
      background-color: $cornflower-blue;
      transform: rotate(45deg);
    }
    &:after {
      content: "";
      position: absolute;
      bottom: 2px;
      right: 0px;
      width: 50%;
      height: 2px;
      background-color: $cornflower-blue;
      transform: rotate(-45deg);
    }
  }
  .x-down {
    position: relative;
    width: 100%;
    height: 50%;
    &:before {
      content: "";
      position: absolute;
      top: 5px;
      left: 4px;
      width: 50%;
      height: 2px;
      background-color: $cornflower-blue;
      transform: rotate(-45deg);
    }
    &:after {
      content: "";
      position: absolute;
      top: 5px;
      right: 1px;
      width: 50%;
      height: 2px;
      background-color: $cornflower-blue;
      transform: rotate(45deg);
    }
  }
  .is-type & {
    &:before {
      opacity: 1;
      animation: spin 0.85s infinite;
    }
    .x-up {
      &:before, &:after {
        animation: color-1 0.85s infinite;
      }
      &:after {
        animation-delay: 0.3s;
      }
    }
    .x-down {
      &:before, &:after {
        animation: color-1 0.85s infinite;
      }
      &:before {
        animation-delay: 0.2s;
      }
      &:after {
        animation-delay: 0.1s;
      }
    }
  }
}

.icon-search {
  position: relative;
  top: 5px;
  left: 8px;
  width: 50%;
  height: 50%;
  opacity: 1;
  border-radius: 50%;
  border: 3px solid mix($cornflower-blue, white, 35%);
  transition: opacity 0.25s ease, transform 0.43s $snappy;
  &:after {
    content: "";
    position: absolute;
    bottom: -9px;
    right: -2px;
    width: 4px;
    border-radius: 3px;
    transform: rotate(-45deg);
    height: 10px;
    background-color: mix($cornflower-blue, white, 35%);
  }
}

.field {
  border: 0;
  width: 100%;
  height: 100%;
  padding: 10px 20px;
  background: white;
  border-radius: 3px;
  box-shadow: 0px 8px 15px rgba($tundora, 0.1);
  transition: all 0.4s ease;
  &:focus {
    outline: none;
    box-shadow: 0px 9px 20px rgba($tundora, 0.3);
    + .icons-container {
      .icon-close {
        opacity: 1;
        transform: translateX(0);
      }
      .icon-search {
        opacity: 0;
        transform: translateX(200%);
      }
    }
  }
}
$(document).on('ready', function() {
  
  $('.field').on('focus', function() {
    $('body').addClass('is-focus');
  });
  
  $('.field').on('blur', function() {
    $('body').removeClass('is-focus is-type');
  });
  
  $('.field').on('keydown', function(event) {
    $('body').addClass('is-type');
    if((event.which === 8) && $(this).val() === '') {
      $('body').removeClass('is-type');
    }
  });
  
});

External CSS

  1. https://codepen.io/rickzanutta/pen/YXqdLj

External JavaScript

  1. //cdnjs.cloudflare.com/ajax/libs/jquery/2.2.2/jquery.min.js