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.

            
              - var d = "7894561230".split(""), ops = "+-*/".split(""), count = d.length

mixin looped_radios(prefix)
  - var x = 0
  while x < count
    if x == 6
      input(type="radio" id=(prefix + '_' + x) name=(prefix) value=(d[x]) checked="true")
    else    
      input(type="radio" id=(prefix + '_' + x) name=(prefix) value=(d[x]))
    - x++
    
mixin looped_labels(prefix)
  - var x = 0
  while x < count
    label(for=(prefix + '_' + x))=d[x]
    - x++

mixin looped_op_radios()
  - var x = 0
  while x < ops.length
    if x == 0
      input(type="radio" id=('ops_' + x) name="ops" value=(ops[x]) checked="true")
    else    
      input(type="radio" id=('ops_' + x) name="ops" value=(ops[x]))
    - x++
    
mixin looped_op_labels()
  - var x = 0
  while x < ops.length
    label(for=('ops_' + x))=ops[x]
    - x++

+looped_op_radios()
+looped_radios("d1")
+looped_radios("d2")

section
  h1 CSS Calculator
  .dig
    +looped_labels("d1")
  .ops
    +looped_op_labels()
  .dig
    +looped_labels("d2")
  .result

    
            
          
!
            
              @import url(https://fonts.googleapis.com/css?family=Roboto+Condensed:300italic,700italic);

//
// ui vars

$c-gray: #999;
$c-primary: #3BB8C4;
$c-secondary: #FF3D2F;
$ui-corner: 4px;


//
// calculator

$ops: "+","-","*","/";
$dig: 7,8,9,4,5,6,1,2,3,0;

// do the math
@function math($op,$x,$y) {
      @if $op == "+" { @return $x + $y; } 
  @elseif $op == "-" { @return $x - $y; } 
  @elseif $op == "*" { @return $x * $y; } 
  @elseif $op == "/" {
        @if $x == 0 { @return 0; }
    @elseif $y == 0 { @return "∞"; }
    @else { @return $x / $y; }
  } @else {
    @return $x + $y;
  }
}

// for each operation
@for $o from 1 through length($ops) {
  $op: nth($ops, $o);
  // for each x
  @for $x from 1 through length($dig) {
    $x_val: nth($dig, $x);
    // for each y
    @for $y from 1 through length($dig) {
      $y_val: nth($dig, $y);
      [value="#{$op}"]:checked ~ [value="#{$x_val}"]:checked ~ [value="#{$y_val}"]:checked ~ section .result:after {
        // content: "#{$x_val} #{$op} #{$y_val} = #{math($op,$x_val,$y_val)}";
        content: "#{math($op,$x_val,$y_val)}";
      }
    }
    // for each digit input, highlight corresponding label
    #d1_#{$x - 1}:checked ~ section div [for="d1_#{$x - 1}"],
    #d2_#{$x - 1}:checked ~ section div [for="d2_#{$x - 1}"] {
      background: $c-secondary;
      box-shadow: 0px 2px 0px 1px darken($c-secondary, 10%);
      pointer-events: none;
    }
  }
  // for each op input, highlight corresponding label
  #ops_#{$o - 1}:checked ~ section div [for="ops_#{$o - 1}"] {
    background: $c-secondary;
    box-shadow: 0px 2px 0px 1px darken($c-secondary, 10%);
    pointer-events: none;
  }
}

//
// interface

$section-h: 300px;
$label-margin: 8px;
  

body { 
  text-align: center; 
  background: #F0F0F0;
}

input {
  opacity: 0.8;
  pointer-events: none;
  margin-top: 2rem;
}

section {
  display: flex;
  width: 95%;
  max-width: 800px;
  margin: 1.5rem auto 0;
  font-size: 2rem;
  flex-wrap: wrap;
  font-family: Menlo, Andale Mono, monospace;
  padding: 2rem;
  box-sizing: border-box;
  background: darken($c-primary, 35%);
  border-radius: $ui-corner * 2;  
  box-shadow: 0px 4px 0px 4px darken($c-primary, 45%);

  h1 { 
    width: calc(100% - #{$label-margin});
    margin: 0 auto 0;
    font-size: 3rem;
    padding-bottom: 0.5rem;
    color: white;
    text-shadow: 
      $label-margin / -4 $label-margin / -4 0px $c-primary,
      $label-margin / 4 $label-margin / 4 0px $c-secondary;
    text-align: center;
    font-family: Roboto Condensed, sans-serif;
    border-bottom: $label-margin / 2 solid darken($c-primary, 20%);
    
    text-transform: uppercase;
    font-weight: 700;
    // letter-spacing: 0.125em;
  }
  
  div {
    display: flex;
    flex-wrap: wrap;
    margin-top: 1rem;
    &:not(.result) { height: $section-h; }
    
    &.dig { 
      width: 37.5%;
      label {
        background: $c-primary;
        box-shadow: 0px 2px 0px 1px darken($c-primary, 5%);
        line-height: $section-h / 4;
        width: calc(33.33% - #{$label-margin});
        height: calc(25% - #{$label-margin});
        &:last-child {
          width: calc(100% - #{$label-margin});
        }
      }
    }
    &.ops { 
      width: 25%; 
      label {
        background: $c-gray;
        box-shadow: 0px 2px 0px 1px darken($c-gray, 5%);
        line-height: $section-h / 2;
        width: calc(50% - #{$label-margin});
        height: calc(50% - #{$label-margin});
      }
    }
    &.result {
      width: calc(100% - #{$label-margin});
      margin: 1rem $label-margin / 2 0;
      padding: 1rem;
      position: relative;
      height: 3rem;
      background: white;
      color: #444;
      box-shadow: 0px 2px 0px 1px darken(white, 10%);
      border-radius: $ui-corner;
      &::after {
        font-size: 3rem;
        position: absolute;
        top: 50%; left: 50%;
        transform: translate(-50%, -50%);
      }
    }
    
    label {
      cursor: pointer;
      text-align: center;
      color: white;
      margin: $label-margin / 2;
      border-radius: $ui-corner;
      &:hover {
        opacity: 0.9;
      }
      
    }
  }
}

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

Console