cssAudio - Activefile-genericCSS - ActiveGeneric - ActiveHTML - ActiveImage - ActiveJS - ActiveSVG - ActiveText - Activefile-genericVideo - ActiveLovehtmlicon-personicon-teamoctocatpop-outspinnerstartv

Pen Settings

CSS Base

Vendor Prefixing

Add External CSS

These stylesheets will be added in this order and before the code you write in the CSS editor. You can also add another Pen here, and it will pull the CSS from it. Try typing "font" or "ribbon" below.

Quick-add: + add another resource

Add External JavaScript

These scripts will run in this order and before the code in the JavaScript editor. You can also link to another Pen here, and it will run the JavaScript from it. Also try typing the name of any popular library.

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.

            
              <div class="item">
  <h3 id="item_title">
    Fancy Item
  </h3>
  <p>
    A description about said fancy item.
  </p>
  <div class="item__actions">
    <button type="button"
            class="demo-btn"
            id="add_me" 
            aria-pressed="false" 
           aria-describedby="item_title">
      <span class="demo-btn__txt">
        Add to Cart
      </span>
      <span class="demo-btn__check">
        <svg fill="#fff" viewBox="0 0 100 100" aria-hidden="true"><g><path fill-rule="evenodd" clip-rule="evenodd" d="M39.363,79L16,55.49l11.347-11.419L39.694,56.49L72.983,23L84,34.085L39.363,79z"/></g></svg>
      </span>
    </button>
  </div>
</div>


<button type="submit">
  Check Out
</button>
            
          
!
            
              /*
  Shared button styles
*/
// Removes outline from submit buttons in Firefox
input[type="submit"]::-moz-focus-inner,
button[type="submit"]::-moz-focus-inner,
button:-moz-focusring,
input:-moz-focusring {
  outline: 0;
}


// Removes inner padding & border in Firefox 4+
button::-moz-focus-inner,
input::-moz-focus-inner {
  border: 0;
  padding: 0;
}

%btns {
  border: 0;
  font-size: inherit;
  font-weight: 500;
  letter-spacing: .02em;
  
  &:focus {
    outline-offset: 4px;
    outline: 3px solid #06aed5;
  }
}

/*
  Default Toggle Button Styles
*/
.demo-btn {
  @extend %btns;
  background: green;
  color: #fff;
  min-width: 200px;
  overflow: hidden;
  padding: 20px;
  position: relative;
  
  &:hover {
    background: darken(green, 5%);
  }
    
  // spans hold the button text and svg
  span {
    left: 0;
    position: absolute;
    pointer-events: none;
    top: 50%;
    transform: translateY(-50%);
    transition: text-indent .2s ease-in-out;
    width: 100%;
  }
  
  // checkmark svg sizing
  svg {
    height: 26px;
    width: 26px;
  }
}

/*
  Initial Text and checkmark positioning
*/
.demo-btn__txt {
  text-indent: 0%;
}

.demo-btn__check {
  text-indent: 200%;
}


/* 
  Styles for 'pressed' button state
*/
.demo-btn[aria-pressed="true"] {
  background: darkred;
  
  // update position of text
  .demo-btn__txt {
    text-indent: -20%;
  }
  
  // move checkmark into view
  .demo-btn__check {
    text-indent: 60%;
  }
}



/* other demo styling */
body {
  font-family: 'Helvetica', Arial, sans-serif;
  line-height: 1.35;
  padding: 20px;
}

.item {
  border: 1px solid;
  max-width: 400px;
  padding: 20px;

  h3 {
    margin: 0 0 .625em;
  }

  p {
    margin: 0 0 1.25em;;
  }
}


button[type="submit"] {
  @extend %btns;
  background: #faba4c;
  border: 2px solid;
  color: #000;
  margin-top: 1.25em;
  padding: .5em 1.25em;
  
  &:hover,
  &:focus {
    background: lighten(#faba4c, 5%);
  }
}
            
          
!
            
              var myBtn = document.getElementById('add_me');

myBtn.addEventListener('click', function ( e ) {
  /* toggle the pressed state of the button based on
     whatever the current value is */
  myBtn.setAttribute('aria-pressed', e.target.getAttribute('aria-pressed') === 'true' ? 'false' : 'true');
});
            
          
!
999px
Close

Asset uploading is a PRO feature.

As a PRO member, you can drag-and-drop upload files here to use as resources. Images, Libraries, JSON data... anything you want. You can even edit them anytime, like any other code on CodePen.

Go PRO

Loading ..................

Console