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 is required to process package imports. If you need a different preprocessor remove all packages first.

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

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

              
                .controls
  .text Probier uns aus!
  %br
  %table
    %tbody
      %tr.direction
        %th Ausrichtung:
        %td{colspan: 2}
          %input{type: 'radio', name: 'direction', onclick: 'updateDemo();', value: 'justify', checked: true}
          %label{for: 'justify'} horizontal (justify)
        %td{colspan: 2}
          %input{type: 'radio', name: 'direction', onclick: 'updateDemo();', value: 'align'}
          %label{for: 'align'} vertikal (align)
        %td{colspan: 2}
          %input{type: 'radio', name: 'direction', onclick: 'updateDemo();', value: 'place'}
          %label{for: 'place'} beides (place)
      %tr.target
        %th Ziel:
        %td{colspan: 2}
          %input{type: 'radio', name: 'target', onclick: 'updateDemo();', value: 'content', checked: true}
          %label{for: 'content'} komplette Grid (content)
        %td{colspan: 2}
          %input{type: 'radio', name: 'target', onclick: 'updateDemo();', value: 'items'}
          %label{for: 'items'} alle Grid-Items (items)
        %td{colspan: 2}
          %input{type: 'radio', name: 'target', onclick: 'updateDemo();', value: 'self'}
          %label{for: 'self'} einzelnes Grid-Item (self)
      %tr.value
        %th Wert:
        %td
          %input{type: 'radio', name: 'value', onclick: 'updateDemo();', checked: true, value: 'start'}
          %label.underline{for: 'start'} start
        %td
          %input{type: 'radio', name: 'value', onclick: 'updateDemo();', value: 'end'}
          %label{for: 'end'} end
        %td
          %input{type: 'radio', name: 'value', onclick: 'updateDemo();', value: 'center'}
          %label{for: 'center'} center
        %td
          %input{type: 'radio', name: 'value', onclick: 'updateDemo();', value: 'stretch'}
          %label{for: 'stretch'} stretch
        %td
          %input{type: 'radio', name: 'value', onclick: 'updateDemo();', value: 'space-around'}
          %label{for: 'space-around'} space-around
        %td
          %input{type: 'radio', name: 'value', onclick: 'updateDemo();', value: 'space-between'}
          %label{for: 'space-between'} space-between
        %td
          %input{type: 'radio', name: 'value', onclick: 'updateDemo();', value: 'space-evenly'}
          %label{for: 'space-evenly'} space-evenly

.container
  .item
  .item
  .item
  .item
  .item.self
  .item
  .item
  .item
  .item
              
            
!

CSS

              
                .container {
  background-color: #cedafe;
  border-radius: 5px;
  margin-bottom: 2em;
  display: grid;
  grid-template-columns: repeat(3, 50px);
  grid-template-rows: repeat(3, 50px);
  grid-gap: 20px;
  height: 260px; // Höher als nötig, um *-content darzustellen
  width: 260px; // Breiter als nötig, um *-content darzustellen
}

.item {
  background-color: lightgreen;
  border: 2px solid green;
  border-radius: 5px;
  padding: 15px;
}

.self {
  background-color: khaki;
  border-color: darkorange;
}

// Setup/Controls

body {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-direction: column;
  min-height: 100vh;
  margin: 0;
  font-family: Helvetica, Arial, Verdana, sans-serif;
  font-size: .9em;
}

.controls {
  text-align: center;
  margin-top: 0.5em;
  width: 100%;
  
  input {
    display: block;
    margin: 0 auto 5px;
  }
  
  label {
    display: inline-block;
  }
  
  table {
    margin: 0 auto;
    
    th {
      text-align: left;
    }
    
    td {
      text-align: center;
    }
    
    th, td {
      padding: 0.3em;
    }
  }
}

.disabled {
  color: lightgrey;
}

.underline {
  text-decoration: underline;
}
              
            
!

JS

              
                $ ->
  $container = $(".container")
  $self = $(".self")

  window.updateDemo = ->
    target = getCurrentState()[0]
    property = getCurrentState()[1] + '-' + target
    value = getCurrentState()[2]

    handleDifferingOptions(target)
    resetContainer()

    if target is 'self'
      $self.css(property, value)
    else
      $container.css(property, value)

  # Aktuell ausgewählten Werte ermitteln
  window.getCurrentState = ->
    return [$("input:radio[name='target']:checked").val(),
            $("input:radio[name='direction']:checked").val(),
            $("input:radio[name='value']:checked").val()]

  # Komplette Grid hat mehr Eigenschaften als die Items und hat einen anderen Default-Wert
  window.handleDifferingOptions = (target) ->
    $start = $("label[for='start'")
    $stretch = $("label[for='stretch'")

    if target is 'content'
      $("input:radio[value^='space-']").attr('disabled', false)
      $("label[for^='space-']").removeClass('disabled')
      $start.addClass("underline")
      $stretch.removeClass("underline")
    else
      $("input:radio[value^='space-']").attr('disabled', true)
      $("label[for^='space-']").addClass('disabled')
      $start.removeClass("underline")
      $stretch.addClass("underline")
      # Falls ein deaktivierter Button angewählt ist, dann auf stretch ausweichen
      if $("input[name='value']:checked").val().indexOf("space-") >= 0
        $("#stretch").prop("checked", true)
        
  # Alles resetten in den Ursprungszustand
  window.resetContainer = ->
    $container.css('justify-content', '')
    $container.css('align-content', '')
    $container.css('place-content', '')
    $container.css('justify-items', '')
    $container.css('align-items', '')
    $container.css('place-items', '')
    $self.css('justify-self', '')
    $self.css('align-self', '')
    $self.css('place-self', '')
              
            
!
999px

Console