cssAudio - Activefile-genericCSS - ActiveGeneric - ActiveHTML - ActiveImage - ActiveJS - ActiveSVG - ActiveText - Activefile-genericVideo - ActiveLovehtmlicon-new-collectionicon-personicon-teamlog-outoctocatpop-outspinnerstartv

Pen Settings

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URL's added here will be added as <link>s in order, and before the CSS in the editor. If you link to another Pen, it will include the CSS from that Pen. If the preprocessor matches, it will attempt to combine them before processing.

Quick-add: + add another resource

Add External Scripts/Pens

Any URL's added here will be added as <script>s in order, and run before the JavaScript in the editor. You can use the URL of any other Pen and it will include the JavaScript from that Pen.

Quick-add: + add another resource

Code Indentation

     

Save Automatically?

If active, Pens will autosave every 30 seconds after being saved once.

Auto-Updating Preview

If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.

            
              <!-- Basic Search -->
<div class="preview-zone">
  <h4>Basic Search</h4>
  <section class="search" role="search">
    <form action="#" method="get" class="search__form">
      <input id="basic-search" class="search__input" type="search" name="search" maxlength="100" placeholder="I am looking for..." required />
      <button class="search__btn-submit" type="submit">Search</button>
    </form>
  </section>
</div>

<!-- Large Search -->
<div class="preview-zone">
  <h4>Large Search</h4>
  <section class="search search--large" role="search">
    <form action="#" method="get" class="search__form">
      <input id="large-search" class="search__input" type="search" name="search" maxlength="100" placeholder="I am looking for..." required />
      <button class="search__btn-submit" type="submit">Search</button>
    </form>
  </section>
</div>

<!-- Swapped Search -->
<div class="preview-zone">
  <h4>Swapped Search</h4>
  <section class="search search--swap" role="search">
    <form action="#" method="get" class="search__form">
      <input id="swap-search" class="search__input" type="search" name="search" maxlength="100" placeholder="I am looking for..." required />
      <button class="search__btn-submit" type="submit">Search</button>
    </form>
  </section>
</div>

<!-- Large & Swapped Search -->
<div class="preview-zone">
  <h4>Large &amp; Swapped Search</h4>
  <section class="search search--large search--swap" role="search">
    <form action="#" method="get" class="search__form">
      <input id="large-swap-search" class="search__input" type="search" name="search" maxlength="100" placeholder="I am looking for..." required />
      <button class="search__btn-submit" type="submit">Search</button>
    </form>
  </section>
</div>

<!-- Icon Search -->
<div class="preview-zone">
  <h4>Icon Search</h4>
  <section class="search search--icon" role="search">
    <form action="#" method="get" class="search__form">
      <input id="icon-search" class="search__input" type="search" name="search" maxlength="100" placeholder="I am looking for..." required />
      <button class="search__btn-submit" type="submit"></button>
    </form>
  </section>
</div>

<!-- Icon Search (Expandable) -->
<div class="preview-zone">
  <h4>Icon Search (Expandable)</h4>
  <section class="search search--icon search--icon-expandable" role="search">
    <form action="#" method="get" class="search__form">
      <input id="icon-search-expandable" class="search__input" type="search" name="search" maxlength="100" placeholder="I am looking for..." required />
      <button class="search__btn-submit" type="submit"></button>
    </form>
  </section>
</div>

<!-- Icon Search (Expandable with JS) -->
<div class="preview-zone">
  <h4>Icon Search (Expandable with JS)</h4>
  <section id="expandable-search" class="search search--icon search--icon-expandable" role="search">
    <form action="#" method="get" class="search__form">
      <input id="icon-search-expandable-js" class="search__input" type="search" name="search" maxlength="100" placeholder="I am looking for..." />
      <button class="search__btn-submit" type="submit"></button>
    </form>
  </section>
</div>

            
          
!
            
              @import url('https://fonts.googleapis.com/css?family=Open+Sans');

/**
 * Base styles
 */

body {
  padding: 30px;
  font-family: 'Open Sans', sans-serif;
  background-color: #111;
  -webkit-font-smoothing: antialiased;
}

h4 {
  margin-top: 0;
  color: #666;
  text-transform: uppercase;
  letter-spacing: 1px;
}

.preview-zone {
  display: inline-block;
  padding: 30px;
  margin: 15px;
  background-color: #1a1a1a;
}

/**
 * Search styles
 */

// Colors
$input-color: #333;
$button-color: #777;
$icon-color: #666;

// Namespace
$ns: '.search';

#{$ns} {
  &__form {
    display: flex;
  }

  // Large modifier
  &--large {
    #{$ns}__input {
      padding: 30px;
    }
    
    #{$ns}__btn-submit {
      padding: 30px;
    }
  }
  
  // Swapped modifier
  &--swap {
    #{$ns}__input {
      order: 1;
    }
  }
  
  // Icon modifier
  &--icon {
    #{$ns}__form {
      position: relative;
    }

    #{$ns}__btn-submit {
      position: absolute;
      right: 0;
      top: 0;
      padding: 0;
      width: 46px;
      height: 100%;
      background: none;
      
      &:focus,
      &:active,
      &:hover {
        box-shadow: none;
        
        &:before {
          border-color: #eee;
        }
        
        &:after {
          background-color: #eee;
        }
      }
      
      &:before,
      &:after {
        content: '';
        position: absolute;
        transition: background-color 200ms ease-out,
                    border-color 200ms ease-out;
      }
      
      &:before {
        right: 8px;
        top: 8px;
        width: 16px;
        height: 16px;
        border: 3px solid $icon-color;
        border-radius: 100%;
      }
      
      &:after {
        right: 30px;
        top: 23px;
        width: 3px;
        height: 16px;
        background-color: $icon-color;
        transform: rotate(45deg);
      }
      
      &:hover {
        background: none;
      }
    }
  }
  
  // Icon (Expandable) modifier
  &--icon-expandable {
    #{$ns}__input {
      transform: scaleX(0);
      transform-origin: right center;
      transition: transform 300ms ease-out;
      
      &:focus,
      &:active {
        transform: scaleX(1);
      }
    }
    
    #{$ns}__btn-submit {
      background-color: $input-color;
      
      &:hover {
        background-color: $input-color;
      }
    }
  }
  
  &--expanded {
    #{$ns}__input {
      transform: scaleX(1);
    }
  }
  
  &__input,
  &__btn-submit {
    &:focus,
    &:active {
      outline: 0;
      box-shadow: 0 0 16px rgba(255, 255, 255, 0.5);
    }
  }

  &__input {
    padding: 15px;
    width: 300px;
    color: #eee;
    font-size: 14px;
    background-color: $input-color;
    border: 0;
  }
  
  &__btn-submit {
    position: relative;
    padding: 15px;
    color: #eee;
    font-size: 13px;
    background-color: #666;
    border: 0;
    text-transform: uppercase;
    letter-spacing: 1px;
    cursor: pointer;
    z-index: 10;
    transition: background-color 200ms ease-out;
    
    &:hover {
      background-color: $button-color;
    }
  }
}

            
          
!
            
              // Cache some selectors
const $expandableSearch = document.getElementById('expandable-search')
const $expandableSearchBtn = $expandableSearch.querySelector('.search__btn-submit')
const $expandableSearchInput = $expandableSearch.querySelector('.search__input')

// Attach click event handler on search icon
$expandableSearchBtn.addEventListener('click', function (e) {

  e.preventDefault()

  const expanded = $expandableSearch.getAttribute('data-expanded')

  // Toggle expanded state class and store in data attribute
  if (expanded === null || expanded === 'false') {
    $expandableSearch.setAttribute('data-expanded', 'true')
    $expandableSearch.classList.add('search--expanded')
    $expandableSearchInput.focus()
  } else {
    $expandableSearch.setAttribute('data-expanded', 'false')
    $expandableSearch.classList.remove('search--expanded')
  }
})


            
          
!
999px
Loading ..................

Console