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

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

              
                  <div class="container-fluid">
    <div class="row d-flex flex-column vh-100 py-5">
      <div class="col d-flex align-items-center py-3 position-relative" id="displayArea">
        <div id="errors" class="position-absolute text-center px-3" style="left: 0;right: 0;">
          <p id="noblank" class="d-none display-1 text-uc">You should clear a cell</p>
          <p id="manyblank" class="d-none display-1 text-uc">Too many blanks there guy</p>
          <p id="notnumber" class="d-none display-1 text-uc">Your numbers are a failure</p>
          <p id="zero" class="d-none display-1 text-uc">You tryin'a divide by zero</p>
          <p id="displayFactor" class="d-none"></p>
        </div>
        <div class="mx-auto" id="displayareacont" style="width: 480px; height: 252px;">
          <div class="position-absolute" id="red" style="width: 480px; height: 252px;"></div>
          <div class="position-absolute" id="blue" style="width: 280px; height: 147px;"></div>
        </div>
      </div>
      <div class="col flex-grow-0" id="controls">
        <form role="calculate" class="container" novalidate>
          <div class="row mx-n1">
            <div class="col px-1">
              <input type="text" id="a" value="1200" autocomplete="off" onkeydown="javascript: return event.which === 190 || event.keyCode === 8 || event.keyCode === 9 || event.keyCode === 46 ? true : !isNaN(Number(parseInt(event.key)))" onClick="this.setSelectionRange(0, this.value.length)" pattern="[0-9]*" class="w-100 mb-2 px-2 py-1">
            </div>
            <div class="col px-1">
              <input type="text" id="b" value="630" autocomplete="off" onkeydown="javascript: return event.which === 190 || event.keyCode === 8 || event.keyCode === 9 || event.keyCode === 46 ? true : !isNaN(Number(parseInt(event.key)))" onClick="this.setSelectionRange(0, this.value.length)" pattern="[0-9]*" class="w-100 mb-2 px-2 py-1">
            </div>
          </div>
          <div class="row mx-n1">
            <div class="col px-1">
              <input type="text" id="c" value="700" autocomplete="off" onkeydown="javascript: return event.which === 190 || event.keyCode === 8 || event.keyCode === 9 || event.keyCode === 46 ? true : !isNaN(Number(parseInt(event.key)))" onClick="this.setSelectionRange(0, this.value.length)" pattern="[0-9]*" class="w-100 mb-2 px-2 py-1">
            </div>
            <div class="col px-1">
              <input type="text" id="d" value="" autocomplete="off" onkeydown="javascript: return event.which === 190 || event.keyCode === 8 || event.keyCode === 9 || event.keyCode === 46 ? true : !isNaN(Number(parseInt(event.key)))" onClick="this.setSelectionRange(0, this.value.length)" pattern="[0-9]*" class="w-100 mb-2 px-2 py-1">
            </div>
          </div>
          <div class="row">
            <div class="col">
              <div class="form-check mb-2">
                <input class="form-check-input bg-dark" type="checkbox" id="solveD" name="solveD" checked>
                <label class="form-check-label" for="solveD">Always solve for bottom-right position</label>
              </div>
            </div>
          </div>
          <div class="row">
            <div class="col">
              <button class="btn btn-dark w-100 mb-2" type="button" id="calc" name="calculate">Calculate</button>
            </div>
          </div>
        </form>
      </div>
    </div>
  </div>
              
            
!

CSS

              
                body {
  overflow: hidden;
}
.hide {
  display: none;
}
.text-uc {
  text-transform: uppercase;
}
/* DISPLAY AREA */
#red,
#blue,
#displayareacont {
  -webkit-transition: all 1s;
  transition: all 1s;
}
#displayareacont {
  width: 20px;
  height: 20px;
  display: block;
  opacity: 1;
}
#displayareacont.d-none {
  opacity: 0;
  display: block !important;
}
#red,
#blue {
  height: 20px;
  width: 20px;
  background-blend-mode: multiply;
}
#red,
#a,
#b {
  border: solid 1px #19191a;
  background: rgba(255, 0, 0, 0.2);
}
#blue,
#c,
#d {
  border: dashed 1px #19191a;
  background: rgba(0, 0, 255, 0.2);
}

              
            
!

JS

              
                $("#calc").click(function () {
  var prop = [0, 1, 2, 3], // a/b=c/d
    numInvalid = 0, // clear error codes
    numBlanks = 0,
    zeroError = 0,
    displayH = $("#displayArea").height(), //get display area h/w
    displayW = $("#displayArea").width(),
    displayFactor = 1; //display factor

  // assign values to a/b=c/d
  prop[0] = $("#a").val();
  prop[1] = $("#b").val();
  prop[2] = $("#c").val();
  prop[3] = $("#d").val();

  // clear bottom right if checked
  if ($("#solveD").is(":checked")) {
    prop[3] = "";
  }

  // check proportions for invalid number, too many blanks, zeroes -- log that error!

  for (var i = 0; i < prop.length; i++) {
    if (isNaN(prop[i])) {
      numInvalid = true;
    }
    if (prop[i] == "") {
      numBlanks++;
    }
    if (prop[i] == 0 && prop[i].length != 0) {
      zeroError = true;
    }
  }

  // check for errors... display the error
  $("#manyblank,#noblank,#notnumber,#zero,#displayFactor").addClass("d-none");
  if (numBlanks < 1) {
    $("#noblank").removeClass("d-none");
  } else if (numBlanks > 1) {
    $("#manyblank").removeClass("d-none");
  } else if (numInvalid) {
    $("#notnumber").removeClass("d-none");
  } else if (zeroError) {
    $("#zero").removeClass("d-none");
  } else {
    $("#displayareacont").removeClass("d-none");
    // if no errors... figure out which one was blank and solve
    if (prop[0] == "") {
      prop[0] = Math.round((prop[2] / prop[3]) * prop[1] * 1000) / 1000;
      $("#a").val(prop[0]);
    } else if (prop[1] == "") {
      prop[1] = Math.round((prop[3] / prop[2]) * prop[0] * 1000) / 1000;
      $("#b").val(prop[1]);
    } else if (prop[2] == "") {
      prop[2] = Math.round((prop[0] / prop[1]) * prop[3] * 1000) / 1000;
      $("#c").val(prop[2]);
    } else if (prop[3] == "") {
      prop[3] = Math.round((prop[1] / prop[0]) * prop[2] * 1000) / 1000;
      $("#d").val(prop[3]);
    }
    // See if we need to shrink the display factor for the red and blue boxes
    if (prop[1] > displayH || prop[3] > displayH || prop[0] > displayW || prop[2] > displayW) {
      displayFactor = Math.min(
        displayH / Math.max(prop[1], prop[3]),
        displayW / Math.max(prop[0], prop[2])
      );
      $("#displayFactor")
        .removeClass("d-none")
        .html("Displaying at ~" + Math.round(displayFactor * 10000) / 100 + "%")
        .addClass("error");
    }

    // Update the red and blue boxes with.
    $("#red").css({
      width: prop[0] * displayFactor,
      height: prop[1] * displayFactor
    });
    $("#blue").css({
      width: prop[2] * displayFactor,
      height: prop[3] * displayFactor
    });

    $("#displayareacont").css({
      width: Math.max(prop[0], prop[2]) * displayFactor,
      height: Math.max(prop[1], prop[3]) * displayFactor
    });
  }
});

              
            
!
999px

Console