Pen Settings

HTML

CSS

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URLs added here will be added as <link>s in order, and before the CSS in the editor. You can use the CSS from another Pen by using its URL and the proper URL extension.

+ add another resource

JavaScript

Babel includes JSX processing.

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.

+ add another resource

Packages

Add Packages

Search for and use JavaScript packages from npm here. By selecting a package, an import statement will be added to the top of the JavaScript editor for this package.

Behavior

Auto Save

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.

Format on Save

If enabled, your code will be formatted when you actively save your Pen. Note: your code becomes un-folded during formatting.

Editor Settings

Code Indentation

Want to change your Syntax Highlighting theme, Fonts and more?

Visit your global Editor Settings.

HTML

              
                <!-- from https://dribbble.com/shots/3945978-Alignment-button -->

<div class="c-container">
  <div class="align-btn">
    <div class="align-btn__left t-left selected" role="presentation" data-btn="left" id="selected">
      <span class="align-line1"></span>
      <span class="align-line2"></span>
      <span class="align-line3"></span>
    </div>
    <button class="align-btn__left t-left" id="left">
      <span class="align-line1"></span>
      <span class="align-line2"></span>
      <span class="align-line3"></span>
    </button>
        <button class="align-btn__center t-center" id="center">
      <span class="align-line1"></span>
      <span class="align-line2"></span>
      <span class="align-line3"></span>
    </button>
        <button class="align-btn__right t-right" id="right">
      <span class="align-line1"></span>
      <span class="align-line2"></span>
      <span class="align-line3"></span>
    </button>
    
  </div>

</div>
<!-- logo grid for design credits -->
<a href="https://dribbble.com/shots/3945978-Alignment-button" target="_blank">
  <div class="u-logo">
    Design from  
    <svg xmlns="http://www.w3.org/2000/svg" width="132" class="u-logo__svg" height="32" viewBox="0 0 132 32" fill="none">
<rect width="131.556" height="32" fill="%232B2B2B" fill-opacity="0"></rect>
<path fill-rule="evenodd" clip-rule="evenodd" d="M131.352 25.2639C125.854 34.5449 117.148 31.8518 114.533 29.7433C113.42 30.4952 111.469 32.1431 108.867 31.953C103.325 31.5478 101.341 23.6623 101.341 23.6623C101.381 23.6939 99.6903 24.2432 98.7766 24.2335C98.7648 26.5459 96.7573 32.0699 91.3398 31.9993C85.2603 31.9204 84.0244 22.9014 84.0244 22.9014C84.0244 22.9014 83.4194 23.7379 81.1191 24.5711C81.2348 22.7945 81.1501 31.7289 73.8638 31.8602C68.1035 31.9641 66.5484 22.7623 66.5484 22.7623C66.5484 22.7623 65.549 23.796 63.6124 24.1545C63.7355 22.349 63.5355 31.8905 56.2481 31.8602C51.3235 31.8397 49.6406 26.1918 49.7715 25.408C49.9385 24.4088 48.1071 32.0007 43.3235 31.8824C41.3495 31.8246 39.8777 30.4015 38.9543 28.5039C37.7181 29.9126 35.9231 31.8824 33.9096 31.8824C30.2954 31.8824 28.7019 28.8722 28.9718 20.2744C28.9948 19.2548 28.9209 18.8536 27.903 18.7011C27.2919 18.5996 26.6661 18.4075 26.0041 18.306C25.7919 19.0112 23.9919 31.6529 17.8027 31.8928C15.7264 31.9735 14.5911 30.1824 13.6587 28.853C12.2294 30.7358 10.3427 31.953 7.65493 31.953C3.10203 31.953 0 28.2879 0 23.7668C0 19.2457 3.10203 15.581 7.65493 15.581C8.45992 15.581 8.6859 15.6959 9.42132 15.9096C7.90892 2.19775 11.4806 0.0547897 14.6051 0.0547897C17.6047 0.0547897 22.7294 6.98749 15.5186 24.5725C17.1195 29.8176 20.5707 29.5209 22.2293 18.7236C22.5667 16.5287 21.6642 13.567 23.0681 13.1536C25.6343 12.3982 25.9066 14.6648 27.1097 15.0424C28.3821 15.4416 29.1247 15.4026 30.346 15.6566C32.4331 16.0624 33.2476 17.1788 32.9932 19.6653C32.6879 22.8117 32.1538 27.3909 33.7824 27.9489C34.9569 28.3544 37.1013 25.9291 37.4775 24.602C37.8537 23.275 37.9323 22.8207 37.9657 21.8474C38.0167 19.7671 38.0804 18.2422 38.4367 16.6688C38.5892 16.0601 38.763 15.6569 39.4547 15.6294C40.0238 15.6149 41.0647 15.4442 41.5229 15.7994C42.1336 16.2563 42.0573 16.7199 41.9871 17.9401C41.2769 35.3378 46.7434 26.6528 48.3733 19.6986C47.793 11.8351 48.1915 0.198785 53.14 0.00362164C55.7137 -0.0978739 56.8514 1.95518 56.9765 3.4876C57.3305 7.81568 55.3476 14.9851 52.7399 19.8065C51.2496 29.6443 59.2563 31.5896 60.5367 23.737C58.4418 22.7452 56.1779 18.7308 58.0201 16.7744C59.0539 15.6765 63.357 17.2539 63.4275 20.6938C65.5382 20.1317 65.82 18.9451 65.8493 19.1417C65.269 11.2782 65.8071 0.198885 70.756 0.00372212C73.3293 -0.0977734 74.467 1.95528 74.5922 3.4877C74.9461 7.81578 72.9633 14.9852 70.3559 19.8066C68.8653 29.6444 76.8723 31.5896 78.1524 23.7371C76.6014 23.4391 73.3273 19.1693 75.2164 16.7745C76.2259 15.4948 80.5131 18.156 80.9932 20.8078C83.021 20.2363 83.2963 19.0873 83.3253 19.2808C82.745 11.4175 83.2831 0.338244 88.232 0.143081C90.8053 0.0415859 91.943 2.09464 92.0682 3.62705C92.4221 7.95514 90.4393 15.1247 87.8316 19.9462C86.3413 29.7839 94.348 31.7288 95.6284 23.8763C93.4971 23.5229 90.4679 19.0145 92.906 16.7081C93.88 15.7866 97.6018 18.1786 98.473 20.9077C99.6835 20.8613 100.437 20.4457 100.599 20.4037C98.6659 11.1725 100.105 0.0963155 105.428 0.00385746C108.306 -0.0460672 111.119 1.55286 109.884 10.3352C108.705 18.7145 104.469 22.2311 104.479 22.2849C104.725 23.2887 106.899 31.6899 112.374 27.2572C112.09 26.6182 111.806 25.9654 111.648 25.1745C110.741 20.5681 112.523 15.365 117.367 14.524C120.142 14.0423 122.757 15.3878 123.17 18.4212C123.85 23.3848 119.349 26.9797 117.638 27.7594C116.871 27.3257 124.587 32.2533 129.166 22.3783C129.432 21.8145 129.752 21.8622 130.166 22.1528C130.459 22.3581 132.128 23.9318 131.352 25.2639ZM10.9668 22.5472C10.7338 21.8535 10.2556 20.3252 10.0865 19.663C9.15532 18.8567 8.49065 18.7256 7.29537 18.7256C4.63907 18.7256 3.07561 21.1711 3.07561 23.8081C3.07561 26.4451 4.77888 28.891 7.43518 28.891C9.73719 28.891 11.4892 27.3324 12.0237 25.1261C11.6496 24.266 11.2785 23.4755 10.9668 22.5472ZM14.54 3.6844C12.6735 3.6844 12.0404 8.11802 12.1633 11.9003C12.2719 15.2443 13.2103 18.1884 13.6971 19.5074C13.8207 19.6727 13.7978 19.5652 13.9081 19.7406C17.1489 12.6699 15.8047 3.6844 14.54 3.6844ZM53.4066 3.82366C50.9942 3.54817 51.0097 13.5548 51.3093 15.7994C52.5621 13.8035 54.7386 4.36104 53.4066 3.82366ZM71.0222 3.82366C68.6099 3.54817 68.6254 13.5548 68.925 15.7994C70.1777 13.8035 72.3543 4.36104 71.0222 3.82366ZM88.4982 3.96289C86.0859 3.68739 86.1014 13.694 86.401 15.9388C87.6537 13.9428 89.8303 4.50023 88.4982 3.96289ZM105.695 3.2379C101.936 3.98946 102.811 16.4679 103.382 18.6564C107.809 12.6015 107.9 3.01046 105.695 3.2379ZM119.78 18.8318C119.589 18.0362 118.634 17.6109 117.974 17.7157C116.087 17.9724 114.257 20.3127 114.965 23.876C115.123 24.6695 115.518 25.3999 115.511 25.3757C119.735 22.5543 120.094 20.3309 119.78 18.8318ZM40.1946 12.8751C39.6552 12.8752 39.1279 12.716 38.6794 12.4177C38.2308 12.1194 37.8812 11.6953 37.6748 11.1991C37.4683 10.7029 37.4142 10.1569 37.5194 9.63014C37.6246 9.10336 37.8843 8.61947 38.2657 8.23966C38.647 7.85986 39.1329 7.6012 39.662 7.4964C40.191 7.3916 40.7393 7.44537 41.2376 7.65091C41.7359 7.85644 42.1619 8.20452 42.4615 8.6511C42.7612 9.09769 42.9211 9.62273 42.921 10.1598C42.9211 10.5164 42.8506 10.8694 42.7135 11.1989C42.5765 11.5283 42.3757 11.8276 42.1225 12.0797C41.8694 12.3319 41.5688 12.5319 41.238 12.6684C40.9072 12.8048 40.5526 12.8751 40.1946 12.8751Z" fill="#2B2B2B"></path>
</svg>
  </div>
</a>
              
            
!

CSS

              
                //text color
$bg: linear-gradient(180deg,#E7E7E7, #E7E7E7)
$text: rgb(66, 66, 66)
$btn: rgb(0, 87, 183)
$btn-size: 2em
$btn-line-default: #E7E7E7
$btn-line-selected: #2B2B2B

$line-margin: 0.25em 0
$btn-radius: 10px

$cubic: cubic-bezier(.39,.58,.57,1)

//mobile query based on bootstrap
$phone: "only screen and (min-width : 576px)"
$tablet: "only screen and (min-width : 768px)"
$laptop: "only screen and (min-width : 992px)"
$desktop: "only screen and (min-width : 1200px)"
  
@mixin flex-center
  display: flex
  justify-content: center
  align-items: center

body
  font-family: 'Lato', sans-serif
  width: 100%
  height: 100vh
  min-height: 100%
  background: $bg
  @include flex-center
    
a
  color: white
  
.c-container
  max-width: 90vw
  width: 100%
  height: 100%
  max-height: 60vh
  border-radius: 2em
  @include flex-center
  @media #{$tablet}
    max-width: 50vw
    width: 100%
    height: 100%
    max-height: 60vh

// dribbble logo settings
.u-logo
  position: absolute
  right: 1em
  bottom: 1em
  color: #2B2B2B
  &__svg
    margin-left: 0.5em
  &:hover
    opacity: 0.9
    cursor: pointer

//mixin for button settings
@mixin align-btn
  width: $btn-size
  height: $btn-size
  background: white
  border: 0
  border-radius: $btn-radius
  &:hover
    cursor: pointer
  &:active
    outline: none
    transform: translateY(1px)
  
  span[class^="align"]
    display: block
    width: 100%
    height: 2px
    background: $btn-line-default
    border-radius: $btn-radius
    transition: ease 400ms
    animation-fill-mode: backwards
    &:nth-child(2)
      margin: $line-margin

// mixin for line width and align
@mixin btn-line-width($width)
  @for $i from 1 through length($width)
    span.align-line#{$i}
      width: nth($width, $i)
  
.align-btn
  position: relative
  background: white
  box-shadow: 1px 1px 3px rgba(0,0,0,0.1)
  border-radius: $btn-radius
  padding: 0.5em
  transition: ease 400ms
  &:active
    transform: scale(0.95)
  &__left, 
  &__center,
  &__right
    @include align-btn
    $list: (100%, 100%, 50%)
    @include btn-line-width($list)
      
//create an element for selected lines and disable pointer events
.selected
  position: absolute
  top: 1.1em
  left: 0.5em
  background: transparent
  width: $btn-size
  height: $btn-size
  padding: 0 0.5em
  max-width: 2em
  box-sizing: border-box
  pointer-events: none
  z-index: 1
  span[class^="align-line"]
    background: $btn-line-selected
    transition: $cubic 500ms
    @for $i from 1 through 3
      &:nth-child(#{$i})
        transition-delay: calc(100ms * #{$i})
    
.align-btn__left.selected
  span
    transform: translateX(0)
    
.align-btn__center.selected
  span
    transform: translateX(2.1em)
  
.align-btn__right.selected
  span
    transform: translateX(4.3em)

//set third line's margin separately
t-left
    &:nth-child(3)
      margin: 0

.t-center
    span:nth-child(3)
      margin: 0 auto
  
.t-right
    span:nth-child(3)
      margin: 0 0 0 auto
              
            
!

JS

              
                (() => {
  const btn = ["left", "center", "right"];

  const triggerBtn = e => {
    const currentBtn = document
      .getElementById("selected")
      .getAttribute("data-btn");
    document.getElementById("selected").className = `align-btn__${
      e.target.id
    } selected t-${currentBtn}`;
    document.getElementById("selected").setAttribute("data-btn", e.target.id);

    setTimeout(
      () =>
        (document.getElementById("selected").className = `align-btn__${
          e.target.id
        } selected t-${e.target.id}`),
      400
    );
  };

  btn.forEach(ele => {
    document.getElementById(ele).addEventListener("click", e => triggerBtn(e));
  });
})();

              
            
!
999px

Console