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 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.
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.
If the stylesheet 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 CSS 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.
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 Skypack, which makes packages from npm not only available on a CDN, but prepares them for native JavaScript ES6 import
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.
<div id="calculator-wrapper">
<div id="calculator-form">
<h2>Screen Size Calculator</h2>
<!-- <div class="input-field field-metric">
<label id="metric-attendees" class="active">Attendees</label>
<label id="metric-budget">Budget</label>
</div> -->
<div class="input-field field-attendees">
<label>Approximately how many attendees will you have?</label>
<input type="range" id="attendees" name="attendees"
min="25" max="2500" value="25" step="25">
<span id="range-value">25</span>
</div>
<div class="input-field field-budget" style="display: none;">
<label>What is your budget?</label>
<input type="range" id="budget" name="budget"
min="25" max="2500" value="25" step="25">
<span id="range-value">25</span>
</div>
<div class="input-field field-weekday">
<label>What Day of The Week Do You Need Your Screen?</label>
<select id="weekday">
<option value="Sun-Wed">Sun-Wed</option>
<option value="Thu-Sat">Thu-Sat</option>
</select>
</div>
</div>
<div id="calculator-results">
<h3>Recommended Screen Size: <span id="results-size">10x7 feet</span></h3>
<p><strong>Price:</strong> <span id="price-wrapper">Starting at $<span id="results-price">299</span></span></p>
<div class="visualization">
<div id="person"><img src="https://www.uoe.com/wp-content/uploads/2019/03/people-dark.png"></div>
<div id="screen-visual" class="a25">10x7 feet</div>
</div>
</div>
</div>
body {
font-family: sans-serif;
}
/* --- Screen Size Calculator --- */
#calculator-wrapper {
border: solid 6px #d62726;
background: #ffffff;
border-radius: 8px;
}
#calculator-form {
background: #d62826;
padding: 30px;
}
#calculator-wrapper h2, #calculator-wrapper label, #range-value {
color: #fff;
}
#range-value {
font-weight: 700;
}
@media only screen and (min-width:990px) {
#calculator-wrapper {
display: grid;
grid-template-columns: 1fr 2fr;
grid-gap: 0;
}
}
#calculator-wrapper .logo {
max-width: 270px;
}
#calculator-wrapper h2 {
font-size: 40px;
margin-bottom: 15px;
margin-top: 0px;
}
#calculator-wrapper label {
display: block;
margin-bottom: 10px;
font-weight: 700;
}
#calculator-wrapper .input-field {
margin-bottom: 15px;
}
#calculator-wrapper button {
padding: 15px 30px;
border-radius: 4px;
color: #fff;
background: #D93332;
border: none;
cursor: pointer;
font-size: 25px;
}
#calculator-wrapper select {
height: 40px;
width: 180px;
font-size: 15px;
border-radius: 4px;
}
#calculator-results {
padding: 30px 25px;
}
#attendees {
width: 350px;
-webkit-appearance: none;
height: 10px;
border-radius: 10px;
background: #111;
outline: none;
opacity: 1;
width: 100%;
padding: 0px 10px;
box-sizing: border-box;
}
#attendees::-webkit-slider-thumb {
-webkit-appearance: none;
appearance: none;
width: 25px;
height: 25px;
background: #D93332;
border: solid 3px #fff;
cursor: pointer;
border-radius: 50%;
box-shadow: 0 5px 12px -2px rgba(0,0,0,0.3);
}
#attendees::-moz-range-thumb {
width: 25px;
height: 25px;
background: #4CAF50;
cursor: pointer;
}
#calculator-wrapper .visualization {
display: flex;
}
#screen-visual {
width: 100px;
height: 70px;
border: solid 8px #444;
border-radius: 6px;
text-align: center;
display: flex;
flex-direction: column;
justify-content: center;
transition: all ease 0.4s;
border-bottom-width: 22px;
border-right-width: 10px;
border-left-width: 10px;
position: relative;
font-weight: 700;
color: #444;
max-width: 100%;
background: #ccc;
box-shadow: inset 0px 0px 15px rgba(0,0,0,0.4);
}
#screen-visual::before, #screen-visual::after {
content: "";
position: absolute;
bottom: -14px;
right: 5px;
width: 20px;
height: 7px;
background: #ccc;
z-index: 999;
border-radius: 50px;
}
#screen-visual::before {
right: -13%;
bottom: -27px;
z-index: 0;
width: 126%;
background: black;
border-radius: 50%;
opacity: 0.2;
height: 11px;
}
#screen-visual::after {
width: 22px;
right: 0;
}
#person {
display: inline;
align-self: flex-end;
margin-right: 10px;
}
#person img {
max-height: 70px;
width: auto;
height: 100%;
}
#screen-visual.a25 {
width: 100px;
height: 70px;
}
#screen-visual.a75 {
width: 120px;
height: 90px;
}
#screen-visual.a250 {
width: 160px;
height: 90px;
}
#screen-visual.a500 {
width: 200px;
height: 120px;
}
#screen-visual.a750 {
width: 260px;
height: 150px;
}
#screen-visual.a1000 {
width: 300px;
height: 170px;
}
#screen-visual.a2500 {
width: 400px;
height: 200px;
}
#screen-visual.a5000 {
width: 520px;
height: 260px;
}
#results-size, #price-wrapper {
color: red;
}
#weekday {
color: black;
font-weight: 600;
}
@media only screen and (max-width:990px) {
#person {
display:none;
}
}
#calculator-wrapper .input-field.field-metric {
display: flex;
margin-bottom: 10px;
}
#calculator-wrapper .input-field.field-metric label {
font-weight: 500;
cursor: pointer;
opacity: 0.7;
display: inline-block;
padding: 5px 0;
margin-right: 10px;
}
#calculator-wrapper .input-field.field-metric label.active {
font-weight: 700;
border-bottom: solid 3px #fff;
opacity: 1;
}
jQuery(document).ready(function() {
// Prices
var low25 = 299
var high25 = 349
var low75 = 349
var high75 = 399
var low250 = 599
var high250 = 649
var low500 = 799
var high500 = 899
var low750 = 1199
var high750 = 1399
var low1000 = 1899
var high1000 = 2099
var low2500 = 2399
var high2500 = 2599
var low5000 = 3499
var high5000 = 3999
// Screen Sizes
var size25 = '10x7 feet'
var size75 = '12x9 feet'
var size250 = '16x9 feet'
var size500 = '20x12 feet'
var size750 = '26x15 feet'
var size1000 = '30x17 feet'
var size2500 = '40x20 feet'
var size5000 = '52x26 feet'
// Regex function plugin to add commas to numbers
jQuery.fn.digits = function(){
return this.each(function(){
jQuery(this).text( jQuery(this).text().replace(/(\d)(?=(\d\d\d)+(?!\d))/g, "$1,") );
})
}
// Adjust range number when changed
jQuery('input[type=range]').on('input', function () {
// Get number of attendees in range slider
var attendeeNumber = jQuery('#attendees').val();
// Insert number of attendees in span
jQuery('#range-value').text(attendeeNumber);
// Add plus sign if it reaches 2500
if( attendeeNumber > 2499) {
jQuery('#range-value').append('+');
}
// Add commas to number
jQuery('#range-value').digits();
});
// Calculator
function generate() {
// Input Values
var attendeeNumber = jQuery('#attendees').val();
var weekDay = jQuery('#weekday').val();
// Determine price - low
if( weekDay === 'Sun-Wed') {
if( (attendeeNumber <= 25) ) {
jQuery('#results-price').text(low25);
jQuery('#results-size').text(size25);
jQuery('#screen-visual').text(size25);
jQuery('#screen-visual').removeClass().addClass('a25');
}
if( (attendeeNumber > 25) && (attendeeNumber <= 75) ) {
jQuery('#results-price').text(low75);
jQuery('#results-size').text(size75);
jQuery('#screen-visual').text(size75);
jQuery('#screen-visual').removeClass().addClass('a75');
}
if( (attendeeNumber > 75) && (attendeeNumber <= 250) ) {
jQuery('#results-price').text(low250);
jQuery('#results-size').text(size250);
jQuery('#screen-visual').text(size250);
jQuery('#screen-visual').removeClass().addClass('a250');
}
if( (attendeeNumber > 250) && (attendeeNumber <= 500) ) {
jQuery('#results-price').text(low500);
jQuery('#results-size').text(size500);
jQuery('#screen-visual').text(size500);
jQuery('#screen-visual').removeClass().addClass('a500');
}
if( (attendeeNumber > 500) && (attendeeNumber <= 750) ) {
jQuery('#results-price').text(low750);
jQuery('#results-size').text(size750);
jQuery('#screen-visual').text(size750);
jQuery('#screen-visual').removeClass().addClass('a750');
}
if( (attendeeNumber > 750) && (attendeeNumber <= 1000) ) {
jQuery('#results-price').text(low1000);
jQuery('#results-size').text(size1000);
jQuery('#screen-visual').text(size1000);
jQuery('#screen-visual').removeClass().addClass('a1000');
}
if( (attendeeNumber > 1000) && (attendeeNumber <= 2499) ) {
jQuery('#results-price').text(low2500);
jQuery('#results-size').text(size2500);
jQuery('#screen-visual').text(size2500);
jQuery('#screen-visual').removeClass().addClass('a2500');
}
if( (attendeeNumber >= 2500) ) {
jQuery('#results-price').text(low5000);
jQuery('#results-size').text(size5000);
jQuery('#screen-visual').text(size5000);
jQuery('#screen-visual').removeClass().addClass('a5000');
}
}
// Determine Price - High
if( weekDay === 'Thu-Sat') {
if( (attendeeNumber <= 25) ) {
jQuery('#results-price').text(high25);
jQuery('#results-size').text(size25);
jQuery('#screen-visual').text(size25);
jQuery('#screen-visual').removeClass().addClass('a25');
}
if( (attendeeNumber > 25) && (attendeeNumber <= 75) ) {
jQuery('#results-price').text(high75);
jQuery('#results-size').text(size75);
jQuery('#screen-visual').text(size75);
jQuery('#screen-visual').removeClass().addClass('a75');
}
if( (attendeeNumber > 75) && (attendeeNumber <= 250) ) {
jQuery('#results-price').text(high250);
jQuery('#results-size').text(size250);
jQuery('#screen-visual').text(size250);
jQuery('#screen-visual').removeClass().addClass('a250');
}
if( (attendeeNumber > 250) && (attendeeNumber <= 500) ) {
jQuery('#results-price').text(high500);
jQuery('#results-size').text(size500);
jQuery('#screen-visual').text(size500);
jQuery('#screen-visual').removeClass().addClass('a500');
}
if( (attendeeNumber > 500) && (attendeeNumber <= 750) ) {
jQuery('#results-price').text(high750);
jQuery('#results-size').text(size750);
jQuery('#screen-visual').text(size750);
jQuery('#screen-visual').removeClass().addClass('a750');
}
if( (attendeeNumber > 750) && (attendeeNumber <= 1000) ) {
jQuery('#results-price').text(high1000);
jQuery('#results-size').text(size1000);
jQuery('#screen-visual').text(size1000);
jQuery('#screen-visual').removeClass().addClass('a1000');
}
if( (attendeeNumber > 1000) && (attendeeNumber <= 2499) ) {
jQuery('#results-price').text(high2500);
jQuery('#results-size').text(size2500);
jQuery('#screen-visual').text(size2500);
jQuery('#screen-visual').removeClass().addClass('a2500');
}
if( (attendeeNumber >= 2500) ) {
jQuery('#results-price').text(high5000);
jQuery('#results-size').text(size5000);
jQuery('#screen-visual').text(size5000);
jQuery('#screen-visual').removeClass().addClass('a5000');
}
}
// Apply comma regex function to price
jQuery('#results-price').digits();
}
// Generate results
jQuery('input[type=range]').on('input', generate);
jQuery('select').on('input', generate);
});
Also see: Tab Triggers