Expanding Input

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

Thumbnail
This awesome code was written by matchboxhero, you can see more from this user in the personal repository.
You can find the original code on Codepen.io
Copyright matchboxhero ©
  • HTML
  • CSS
  • JavaScript
    <h3>Expanding Input's</h3>
<input class="expanding-input" placeholder="Expanding Input!"> 
<input class="expanding-input" placeholder="Me Too!"> 

<input class="expanding-input expanding-input--right" placeholder="I Expand Sideways!"> 

<div style="text-align: center;">
  <input class="expanding-input expanding-input--center" placeholder="Me Too!"> 
</div>

/*Downloaded from https://www.codeseek.co/matchboxhero/expanding-input-jEXEPL */
    @import url(https://fonts.googleapis.com/css?family=Roboto:300|Roboto+Slab);

$base-spacing-unit: 24px;
$form-highlight-color: #008071;
$form-border-color: #cccccc;
$form-border-radius: 0;
$form-transition-time: 500ms;

* {
  box-sizing: border-box;
}

body {
  padding: 1em 5em;
  font-family: 'Roboto', sans-serif;
}

h3 {
  font-family: 'Roboto Slab', serif;
  text-align: center;
}

.expanding-input {
  width: 100%;
  text-align: center;
	padding: $base-spacing-unit/2;
  transition: all $form-transition-time ease;
  border: 1px solid $form-border-color;
  margin-bottom: $base-spacing-unit/2;
  border-radius: $form-border-radius;

  &[placeholder] {
    color: darken($form-border-color, 20%);
  }

  &:focus {
    border: 1px solid $form-highlight-color;
    border-bottom: 10px solid $form-highlight-color;
    box-shadow: 0 none;
    outline: none;
    padding: $base-spacing-unit;
  }

  &:focus[placeholder] {
    color: $form-highlight-color;
  }
  
  &--center {
    width: 75%;
    
    &:focus {
      width: 100%;
    }
    
  }
  
  &--right {
    width: 75%;
    text-align: left;
    
    &:focus {
      padding: $base-spacing-unit/2;
      width: 100%;
      border-left: 10px solid $form-highlight-color;
      border-bottom: 1px solid $form-highlight-color;
    }
    
  }
  
}


/*Downloaded from https://www.codeseek.co/matchboxhero/expanding-input-jEXEPL */
    

Comments