Pen Settings

HTML

CSS

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.

+ 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

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.

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

              
                .body
  .hero
    .callout
      h1 Alternative Styling for UI Elements
      blockquote.
        I'm going to be building a few of these over
        time and hopefully folks find them useful!
    pre.code-from-page

  .wrapper
    .toggle-checkboxes
      h3 Toggle Checkboxes
      p.
        This is a more appealing take on a 
        checkbox as it mimics mobile more closely
        
      .flex
        div Do you want the thing?
        .toggle-container
          input#toggle(type="checkbox")
          label(for="toggle")

    .lightbox-example
      h3 CSS only Lightbox
      p.
        This isn't exactly styling a UI element but it's a helpful trick.
        
      a(href="#image")
        img.thumbnail(src="//www.fillmurray.com/800/400")
      a#image.lightbox(href="javascript:history.back()")
        img(src="//www.fillmurray.com/800/400")

    .accessible-toggle
      h3 Accessible Toggle
      p This can be tabbed to, triggered to open from the keyboard, and the details can be tabbed into for screen readers.
      a#toggle-me(
        aria-expanded="false",
        aria-haspopup="true",
        onClick="toggleDetailExpanded('toggle-me')",
        onKeyup="toggleDetailExpanded('toggle-me')",
        tabindex="0"
      ) Toggle Me!
      .expanded(tabindex="0")
        p Lorem ipsum dolor sit amet consectetur adipisicing elit. Harum deleniti vel facere! Accusantium natus, exercitationem voluptatibus maxime a voluptatem! Quam nesciunt eius quibusdam, velit cum magnam doloremque totam harum reiciendis?

              
            
!

CSS

              
                @function rem($size, $neg: false)
  $remSize: $size / 16
  @if $neg == true
    @return -#{$remSize}rem
  @else
    @return #{$remSize}rem

@mixin fontSize($size)
  font-size: $size
  font-size: rem($size)

@import url('//fonts.googleapis.com/css?family=Saira+Extra+Condensed:500,700|Muli:400,400i,800,800i')

$white: #fff
$black: #262626
$toggle-size: 30px
$toggle-padding: 6px
$toggle-border: 2px

*
  box-sizing: border-box

body
  background: linear-gradient(35deg, rgb(180, 0, 35), rgb(50, 0, 35))
  color: rgba($white, .8)
  font: 400 16px/1.5 Muli, sans-serif
  letter-spacing: .045rem
  min-height: 100vh
  
h1
  font: 500 2.5rem/1 'Saira Extra Condensed', sans-serif
  text-transform: uppercase

h3
  font: 500 1.8rem/1 'Saira Extra Condensed', sans-serif
  text-transform: uppercase

// header stuff
.hero
  align-items: center
  background: linear-gradient(75deg, rgb(25,25,25), rgb(0,0,0))
  display: flex
  height: 400px
  justify-content: center
  overflow: hidden
  padding: 0 2rem
  position: relative
  
  h1,
  blockquote
    color: $white
    z-index: 10

  blockquote
    background: rgba($white, .2)
    border-left: 5px solid $white
    border-radius: 0 rem(5) rem(5) 0
    margin-left: rem(8)
    padding: rem(16)

.code-from-page
  color: $white
  font-size: rem(32)
  line-height: 1.5
  margin: 0 auto
  max-width: 50vw
  opacity: .1
  pointer-events: none
  position: absolute
  transform: matrix(.85, .22, -.65, .75, 0, 0)
// End header stuff
  
.wrapper
  margin: 0 auto
  max-width: 1200px
  padding: 0 2rem
  position: relative
  width: 100%
  
  > div
    border-bottom: 5px solid rgba($white,.1)
    padding:  1rem 0
  
// Checkbox Toggle
.toggle-checkboxes
  color: $white
  font-weight: 500
  
  .flex
    align-items: center
    display: flex
    
  label
    border: $toggle-border solid $white
    border-radius: #{($toggle-size + $toggle-border + $toggle-padding) / 2}
    cursor: pointer
    display: block
    height: #{$toggle-size + $toggle-padding}
    margin-left: #{$toggle-padding * 2}
    position: relative
    transition: all .2s ease-in-out
    width: #{($toggle-size + $toggle-border + $toggle-padding) * 1.5}

    &:before
      background: $white
      border-radius: 50%
      content: ''
      height: #{$toggle-size - $toggle-padding}
      position: absolute
      left: #{$toggle-padding - $toggle-border}
      top: #{$toggle-padding - $toggle-border}
      transition: all .2s ease-in-out
      width: #{$toggle-size - $toggle-padding}
  
  input
    display: none
  
    &:checked + label
      background: rgba($white, .3)
    
      &:before
        left: #{$toggle-size - $toggle-padding}
  
      // I wouldn't really do this, you shouldn't either
      &:after
        animation: cheer 1s infinite
        content: '❤️'
        display: inline-block
        font-weight: bold
        left: #{($toggle-size + $toggle-padding) * 2}
        position: relative
        top: #{$toggle-padding / 1.5}

// CSS Lightbox
.thumbnail
  border: rem(5) solid $white
  transition: all .2s ease-in-out
  width: 400px

  &:hover
    box-shadow: 0 rem(5) rem(10) rgba($black, .3)

.lightbox
  background: rgba($black,.8)
  display: none
  height: 100%
  left: 0
  position: fixed
  text-align: center
  top: 0
  width: 100%
  z-index: 999

.lightbox img
  border: rem(5) solid $white
  box-shadow: 0 0 rem(50) $black
  height: auto
  max-height: 90%
  max-width: 90%
  width: auto

.lightbox:target
  align-items: center
  display: flex
  justify-content: center
  outline: none

// Some Animations
@keyframes cheer
  0%
    transform: scale(1.1)
  50%
    transform: scale(.9)
  100%
    transform: scale(1.1)

// Accessible Content Toggle
.accessible-toggle
  a
    cursor: pointer
    font-weight: 500
    text-decoration: underline

    &:focus
      outline: 5px auto -webkit-focus-ring-color
      outline-offset: 2px

  .expanded
    display: none

    ul
      padding: 0 0 0 1em

    li
      margin-bottom: 15px

  [aria-expanded=true] ~ .expanded
      display: block 
              
            
!

JS

              
                // ---
// This just makes the header use the code
// currently within the pen preview as a
// visual element
// ---

document.querySelector(
  ".code-from-page"
).textContent = document.getElementsByClassName("body")[0].innerHTML;

// Code for Accessible Toggle
const toggleDetailExpanded = (ident) => {
  const detailLink = document.getElementById(ident);
  if (event.keyCode == 32 || event.keyCode == 13 || !event.keyCode) {
    detailLink.attributes["aria-expanded"].value === "false"
    
      ? detailLink.setAttribute("aria-expanded", "true")
      : detailLink.setAttribute("aria-expanded", "false");
  }
};

              
            
!
999px

Console