HTML preprocessors can make writing HTML more powerful or convenient. For instance, Markdown is designed to be easier to write and read for text documents and you could write a loop in Pug.
In CodePen, whatever you write in the HTML editor is what goes within the <body>
tags in a basic HTML5 template. So you don't have access to higher-up elements like the <html>
tag. If you want to add classes there that can affect the whole document, this is the place to do it.
In CodePen, whatever you write in the HTML editor is what goes within the <body>
tags in a basic HTML5 template. If you need things in the <head>
of the document, put that code here.
The resource you are linking to is using the 'http' protocol, which may not work when the browser is using https.
CSS preprocessors help make authoring CSS easier. All of them offer things like variables and mixins to provide convenient abstractions.
It's a common practice to apply CSS to a page that styles elements such that they are consistent across all browsers. We offer two of the most popular choices: normalize.css and a reset. Or, choose Neither and nothing will be applied.
To get the best cross-browser support, it is a common practice to apply vendor prefixes to CSS properties and values that require them to work. For instance -webkit-
or -moz-
.
We offer two popular choices: Autoprefixer (which processes your CSS server-side) and -prefix-free (which applies prefixes via a script, client-side).
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.
You can apply CSS to your Pen from any stylesheet on the web. Just put a URL to it here and we'll apply it, in the order you have them, before the CSS in the Pen itself.
You can also link to another Pen here (use the .css
URL Extension) and we'll pull the CSS from that Pen and include it. If it's using a matching preprocessor, use the appropriate URL Extension and we'll combine the code before preprocessing, so you can use the linked Pen as a true dependency.
JavaScript preprocessors can help make authoring JavaScript easier and more convenient.
Babel includes JSX processing.
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.
You can apply a script from anywhere on the web to your Pen. Just put a URL to it here and we'll add it, in the order you have them, before the JavaScript in the Pen itself.
If the script you link to has the file extension of a preprocessor, we'll attempt to process it before applying.
You can also link to another Pen here, and we'll pull the JavaScript from that Pen and include it. If it's using a matching preprocessor, we'll combine the code before preprocessing, so you can use the linked Pen as a true dependency.
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.
Using packages here is powered by esm.sh, which makes packages from npm not only available on a CDN, but prepares them for native JavaScript ESM usage.
All packages are different, so refer to their docs for how they work.
If you're using React / ReactDOM, make sure to turn on Babel for the JSX processing.
If active, Pens will autosave every 30 seconds after being saved once.
If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.
If enabled, your code will be formatted when you actively save your Pen. Note: your code becomes un-folded during formatting.
Visit your global Editor Settings.
<form name="bmiForm">
<div class="bmi-calculator">
<h1 style="margin-bottom: 1em;">Calculate your BMI</h1>
<div class="bmi-calculator-weight">
<input class="weight-slider" name="realweight" id="myWeight" type="range" min="25" max="180" value="60"/>
<p style="margin-top: 1.8em;">
WEIGHT:
<input name="Teža" id="inputWeight" type="number" value="60" min="25" max="180" step="1" oninput="showValWeight(this.value)"/>
<span id="weight"></span> kg
</p>
</div>
<div class="bmi-calculator-height">
<input class="height-slider" name="realheight" id="myHeight" type="range" min="100" max="220" step="1" value="160">
<p style="margin-top: 1.8em;">
HEIGHT:
<input name="Višina" id="inputHeight" type="number" value="160" min="100" max="220" step="1" oninput="showValHeight(this.value)"/>
<span id="height"></span> cm
</p>
</div>
<input class="gumb" type="button" value="Calculate" onclick="calculateBmi()" style="margin-top: 0.5em">
<p style="margin-top: 1em;font-size: 1.2em;">
<strong>Your BMI:</strong>
<span id="yourbmi" style="font-size: 1.2em;margin-left: 8px;"></span>
</p>
<p></p>
<p>
<span id="evaluationMessage"></span>
</p>
</div>
</form>
/* Import Roboto font from Google Fonts */
@import url('https://fonts.googleapis.com/css?family=Roboto:400,500,700&display=swap');
/*
Define CSS variables for colors
*/
:root {
--background-color: #f6f6f6;
--vigo-color: #f09831;
--slider-color: #A3A3A3;
--input-number-color: #EBEBEB;
}
/* Prepare your work table. 😎 */
* {
box-sizing: border-box;
margin: 0;
padding: 0;
}
/*
Push sliders down from <h1> tag
*/
h1 {
text-align: center;
margin-left: 0.2em;
margin-right: 0.2em;
margin-bottom: 0.9em;
}
/*
Define positioning of the elements inside <body>
*/
html,
body {
height: 100%; width: 100%;
margin: 0; padding: 0;
background-color: var(--background-color);
color: black;
}
body {
display: flex;
justify-content: center;
align-items: center;
font-family: 'Roboto', sans-serif;
}
/*
Styling for calculator <div>
*/
.bmi-calculator {
border: 5px solid white;
-moz-box-shadow: 0px 0px 5px hsl(15, 2%, 55%);
-webkit-box-shadow: 0px 0px 5px hsl(15, 2%, 55%);
box-shadow: 0px 0px 10px hsl(0,0%,73.9%);
padding: 3em;
margin: 2em;
height: 520px;
background-color: white;
}
/*
Styling for div elements wrapping both sliders
*/
.bmi-calculator-weight, .bmi-calculator-height {
/* Positioning */
/*border: dotted 1px red;*/
margin-bottom: 2.2em;
width: 100%;
/* background:
repeating-linear-gradient(90deg, #c8c8c8, #c8c8c8 0.125em /* lines *//*, transparent 0.125em, transparent 1.25em /* space between
*//*) 80% no-repeat;
/*background-size: 100% /* = 10*1.25em + .125em */ /*20%;*/
}
/*
Styling for both sliders
*/
.weight-slider, .height-slider {
width: 100%;
height: 1px;
border-radius: 10px;
background: var(--slider-color); /* Light grey background. */
outline: none; /* Remove outline. */
/*opacity: 0.7; *//* Set transparency (for mouse-over effects on hover) */
/*-webkit-transition: .2s;*/ /* 0.2 seconds transition on hover */
/*transition: opacity .2s;*/
}
/* Mouse-over effects 🖱 računalniška miška */
/*.weight-slider:hover, .height-slider:hover *//*{
opacity: 1; *//* Fully shown on mouse-over *//*
}*/
/* DEFINE STYLING FOR INPUT RANGE SLIDERS & INPUT TYPE NUMBER FOR BROWSER COMPATIBILITY
https://css-tricks.com/styling-cross-browser-compatible-range-inputs-css/
*/
input[type=range] {
-moz-appearance: none; /* Override default CSS styles */
-webkit-appearance: none;
appearance: none;
cursor: pointer;
}
input[type=range]:focus {
outline: none; /* Removes the blue border. You should probably do some kind of focus styling for accessibility reasons though. */
}
input[type=range]::-ms-track {
width: 100%;
cursor: pointer;
}
/* Special styling for WebKit/Blink */
input[type=range]::-webkit-slider-thumb {
-webkit-appearance: none;
border: 2.5px solid var(--vigo-color);
height: 20px;
width: 20px;
border-radius: 40px;
background: white;
cursor: pointer;
margin-top: 0px; /* You need to specify a margin in Chrome, but in Firefox and IE it is automatic */
/* box-shadow: 1px 1px 1px #000000, 0px 0px 1px #0d0d0d; */ /* Add cool effects to your sliders! */
}
/* All the same stuff for Firefox */
input[type=range]::-moz-range-thumb {
/* box-shadow: 1px 1px 1px #000000, 0px 0px 1px #0d0d0d; */
border: 2.5px solid var(--vigo-color);
height: 20px;
width: 20px;
border-radius: 40px;
background: white;
cursor: pointer;
}
/* All the same stuff for IE */
input[type=range]::-ms-thumb {
/* box-shadow: 1px 1px 1px #000000, 0px 0px 1px #0d0d0d; */
border: 2.5px solid var(--vigo-color);
height: 20px;
width: 20px;
border-radius: 40px;
background: white;
cursor: pointer;
}
/* INPUT TYPE NUMBER STYLING*/
input[type=number] {
-moz-appearance: none; /* Override default CSS styles */
-webkit-appearance: none;
cursor: pointer;
/* Real styling part :D */
background: var(--input-number-color);
border-style: none;
height: 30px;
width: 60px;
margin-left: 20px;
margin-right: 10px;
text-align: right;
font-family: 'Roboto', sans-serif;
font-size: 1.5em;
}
input[type=number]:focus {
outline: none; /* Removes the blue border. You should probably do some kind of focus styling for accessibility reasons though. */
}
/*
*** END OF DEFAULT STYLING VALUES FOR INPUT RANGE SLIDERS & INPUT TYPE NUMBER ***
*/
/*
Styling for "Calculate" button
*/
.gumb {
text-align: center;
font-size: 1em;
color: white;
width: 100%;
margin-bottom: 10px;
padding: 11px 32px;
border: none;
background-color: var(--vigo-color);
text-transform: uppercase;
cursor: pointer;
}
/*
Media querie for iPhone 5
*/
@media only screen and (max-width: 325px) {
.bmi-calculator {
height: 560px;
}
h1 {
font-size: 1.5em;
}
}
'use strict';
// Define variables for range sliders
// Weight variables
var weightSlider = document.getElementById("myWeight");
var weightOutput = document.getElementById("inputWeight");
// Height variables
var heightSlider = document.getElementById("myHeight");
var heightOutput = document.getElementById("inputHeight");
// Display slider value
weightOutput.innerHTML = weightSlider.value;
heightOutput.innerHTML = heightSlider.value;
// Update sliders in real time while dragging it
weightSlider.oninput = function () {
weightOutput.innerHTML = this.value;
}
heightSlider.oninput = function () {
heightOutput.innerHTML = this.value;
}
// Change weight-slider value on weight-number input
function showValWeight(newVal) {
weightSlider.value=newVal;
};
// Change height-slider value on height-number input
function showValHeight(newVal) {
heightSlider.value=newVal;
};
// *** Change number input when dragging slider ***
// Add 2 eventListeners for weight and input sliders
weightSlider.addEventListener("input", updateValueWeight);
heightSlider.addEventListener("input", updateValueHeight);
function updateValueWeight(e) {
weightOutput.value = e.srcElement.value;
}
function updateValueHeight(e) {
heightOutput.value = e.srcElement.value;
}
// Calculate BMI
function calculateBmi() {
var weight = document.bmiForm.realweight.value;
var height = (document.bmiForm.realheight.value)/100;
var realbmi = (weight)/Math.pow(height, 2);
var realbmiOutput = document.getElementById("yourbmi");
var messageOutput = document.getElementById("evaluationMessage");
var roundedBmi = realbmi.toFixed(1);
messageOutput.innerHTML = ""; // Clear message before calculating new BMI
realbmiOutput.innerHTML = " " + roundedBmi; // Print BMI
// Appropriate message for your BMI rating
if (roundedBmi > 26) {
messageOutput.innerHTML = "YOU'RE A FAT ASS!!!";
} else {
}
// Console loggings
console.log('Teža: ' + weight + " kg");
console.log('Višina: ' + height + " m");
console.log('BMI: ' + realbmi);
}
Also see: Tab Triggers