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.
<h1>Paper-Checkbox Concept - non Polymer</h1>
<p>Supports IE9+, Chrome (Mobile + Desktop), Safari, Opera, Firefox</p>
<input type="checkbox" id="anId1" class="wskCheckbox" checked="true" />
<label class="wskLabel" for="anId1">Check me out</label>
<input type="checkbox" id="anId2" class="wskCheckbox" />
<label class="wskLabel" for="anId2">I look and feel like Google Material</label>
<input type="checkbox" id="anId3" class="wskCheckbox" />
<label class="wskLabel" for="anId3">But I work even in older browsers</label>
<input type="checkbox" id="anId4" class="wskCheckbox" />
<label class="wskLabel" for="anId4">All you have to do is use regular native HTML elements</label>
<div id="panel">
<h2>About this</h2>
<p>This is a small code snippet demonstrating how it is possible to recreate the style and animations of the latest Google Material elements using regular HTML, CSS and JavaScript.</p>
<p>To use this code all you would need to do is write good semantic HTML. In this case yuo need to have a checkbox and a label targeted at the said checkbox using the "for" attribute. You then simply include the example styles and JavaScript on your page and all your checkboxes will be transformed in to the ones you see here. Happy days.</p>
</div>
/* Extra Styles just for this demo. For core checkbox styles see below. */
body {
font-family: Arial, sans-serif;
}
h1, h2 {
font-family: Roboto, 'Helvetica Neue', Helvetica, Arial, sans-serif;
font-size: 24pt;
font-weight: 300;
}
h2 {
color: #ffffff;
font-size: 18pt;
margin: 10px;
}
p {
color: #4d4d4d;
}
#panel {
background: #2d3d2d;
bottom: 0;
padding: 10px;
position: fixed;
right: 0;
top: 0;
width: 280px;
}
#panel p {
color: #dfdfdf;
margin: 10px;
font-size:10pt;
}
/*
* Core styles required for the checkboxes.
* @author Jason Mayes 2014, www.jasonmayes.com
*/
.wskLabel {
cursor: pointer;
font-size: 12pt;
display: block;
overflow: hidden;
padding-top: 20px;
position: relative;
min-height:40px;
}
.wskCheckbox {
border: 2px solid #5a5a5a;
color: #1d1d1d;
cursor: pointer;
display: inline-block;
float: left;
height: 14px;
margin: 0 20px 20px 20px;
outline-color: #eaeaea;
padding: 0;
position:relative;
width: 14px;
-webkit-transition: all 0.3s ease-in-out;
-moz-transition: all 0.3s ease-in-out;
transition: all 0.3s ease-in-out;
z-index:1;
}
.wskCheckbox.checked {
border-left: 2px solid green;
border-bottom: 4px solid green;
border-top: 1px solid rgba(0,0,0,0);
border-right: 1px solid rgba(0,0,0,0);
-webkit-transform: rotate(-45deg) scaleY(0.5);
-moz-transform: rotate(-45deg) scaleY(0.5);
-ms-transform: rotate(-45deg) scaleY(0.5);
-o-transform: rotate(-45deg) scaleY(0.5);
transform: rotate(-45deg) scaleY(0.5);
}
input[type='checkbox'].wskCheckbox {
display: none;
}
.wskCircle {
background-color:#ccdffd;
-webkit-border-radius: 50%;
-moz-border-radius: 50%;
border-radius: 50%;
display: block;
height: 40px;
left: 9px;
opacity: 0;
position: absolute;
top: 9px;
-webkit-transition: all 0.15s ease-in-out;
-moz-transition: all 0.5s ease-in-out;
transition: all 0.15s ease-in-out;
width: 40px;
z-index:0;
}
.wskCircle.show {
opacity: 1;
}
.wskCircle.flipColor {
background-color: #d2d3d2;
}
/*
* Material Deesign Checkboxes non Polymer.
* Tested and working in: IE9+, Chrome (Mobile + Desktop), Safari,
* Opera, Firefox.
* @author Jason Mayes 2014, www.jasonmayes.com
*/
var wskCheckbox = function() {
var wskCheckboxes = [];
var SPACE_KEY = 32;
function animateCircle(checkboxElement) {
var circle =
checkboxElement.parentNode.getElementsByClassName('wskCircle')[0];
var restore = '';
if (circle.className.indexOf('flipColor') < 0) {
restore = circle.className + ' flipColor';
} else {
restore = 'wskCircle';
}
circle.className = restore + ' show';
setTimeout(function(){
circle.className = restore;
}, 150);
}
function addEventHandler(elem, eventType, handler) {
if (elem.addEventListener) {
elem.addEventListener (eventType, handler, false);
}
else if (elem.attachEvent) {
elem.attachEvent ('on' + eventType, handler);
}
}
function clickHandler(e) {
e.stopPropagation();
if (this.className.indexOf('checked') < 0) {
this.className += ' checked';
} else {
this.className = 'wskCheckbox';
}
animateCircle(this);
}
function keyHandler(e) {
e.stopPropagation();
if (e.keyCode === SPACE_KEY) {
clickHandler.call(this, e);
// Also update the checkbox state.
var cbox = document.getElementById(this.parentNode.getAttribute('for'));
cbox.checked = !cbox.checked;
}
}
function clickHandlerLabel(e) {
var id = this.getAttribute('for');
var i = wskCheckboxes.length;
while (i--) {
if (wskCheckboxes[i].id === id) {
if (wskCheckboxes[i].checkbox.className.indexOf('checked') < 0) {
wskCheckboxes[i].checkbox.className += ' checked';
} else {
wskCheckboxes[i].checkbox.className = 'wskCheckbox';
}
animateCircle(wskCheckboxes[i].checkbox);
break;
}
}
}
function findCheckBoxes() {
var labels = document.getElementsByTagName('label');
var i = labels.length;
while (i--) {
var posCheckbox = document.getElementById(labels[i].getAttribute('for'));
if (posCheckbox !== null && posCheckbox.type === 'checkbox' &&
(posCheckbox.className.indexOf('wskCheckbox') >= 0)) {
var text = labels[i].innerText;
var span = document.createElement('span');
span.className = 'wskCheckbox';
span.tabIndex = i;
var span2 = document.createElement('span');
span2.className = 'wskCircle flipColor';
labels[i].insertBefore(span2, labels[i].firstChild);
labels[i].insertBefore(span, labels[i].firstChild);
addEventHandler(span, 'click', clickHandler);
addEventHandler(span, 'keyup', keyHandler);
addEventHandler(labels[i], 'click', clickHandlerLabel);
var cbox = document.getElementById(labels[i].getAttribute('for'));
if (cbox.getAttribute('checked') !== null) {
span.click();
}
wskCheckboxes.push({'checkbox': span,
'id': labels[i].getAttribute('for')});
}
}
}
return {
init: findCheckBoxes
};
}();
wskCheckbox.init();
Also see: Tab Triggers