Lablel Placeholder

In this example below you will see how to do a Lablel Placeholder with some HTML / CSS and Javascript

Thumbnail
This awesome code was written by ChamaraHarindra, you can see more from this user in the personal repository.
You can find the original code on Codepen.io
Copyright ChamaraHarindra ©

Technologies

  • HTML
  • CSS
  • JavaScript
<!DOCTYPE html>
<html lang="en" >

<head>
  <meta charset="UTF-8">
  <title>Lablel Placeholder</title>
  
  
  <link rel='stylesheet prefetch' href='https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/3.3.7/css/bootstrap.min.css'>

      <link rel="stylesheet" href="css/style.css">

  
</head>

<body>

  <div class="demo">
  <div class="input-group">
    <label class="placeholder">Please enter text to search</label>
      <input type="text" class="form-control">
      <span class="input-group-btn">
        <button class="btn btn-success" type="button">Search</button>
      </span>
    </div>
</div>
  <script src='https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js'></script>

  

    <script  src="js/index.js"></script>




</body>

</html>

/*Downloaded from https://www.codeseek.co/ChamaraHarindra/lablel-placeholder-yKpPNo */
body, html {
  background: #dedede;
}
.demo {
  max-width: 400px;
  margin: 200px auto 0;
}

.input-group {
  position: relative;
}

.placeholder {
  position: absolute;
  z-index: 3;
  top: 50%;
  transform: translateY(-50%);
  left: 15px;
  color: red;
  font-weight: normal;
  display: none;
  cursor: text;
}

/*Downloaded from https://www.codeseek.co/ChamaraHarindra/lablel-placeholder-yKpPNo */
$('.btn-success').on('click', function () {
  if($('.form-control').val() == "") {
    $('.placeholder').show();
  }
})

$('.placeholder').on('click', function() {
  $('.placeholder').hide();
  $('.form-control').focus();
})

Comments