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.
<div class="wrapper">
<hgroup>
<h1>CSS Filter Glass</h1>
<h3>drag an image file from your desktop onto the glass</h3>
</hgroup>
<div class="window">
<div class="glass left img"></div>
<div class="handle"></div>
<div class="glass right filter-grayscale img"></div>
</div>
<ul class="filter-choice">
<li data-filter="grayscale">
<input type="radio" name="filter-choice-group" value="grayscale" class="filter-grayscale img" checked>
</li>
<li data-filter="sepia">
<input type="radio" name="filter-choice-group" value="sepia" class="filter-sepia img">
</li>
<li data-filter="blur">
<input type="radio" name="filter-choice-group" value="blur" class="filter-blur img">
</li>
<li data-filter="brightness">
<input type="radio" name="filter-choice-group" value="brightness" class="filter-brightness img">
</li>
<li data-filter="contrast">
<input type="radio" name="filter-choice-group" value="contrast" class="filter-contrast img">
</li>
<li data-filter="hue-rotate">
<input type="radio" name="filter-choice-group" value="hue-rotate" class="filter-hue-rotate img">
</li>
<li data-filter="invert">
<input type="radio" name="filter-choice-group" value="invert" class="filter-invert img">
</li>
<li data-filter="saturate">
<input type="radio" name="filter-choice-group" value="saturate" class="filter-saturate img">
</li>
<li class="alt">
<a href="https://www.google.com/chrome" target="_blank">
<img src="http://kindofone.me/resources/icons/chrome-512.png" width="32" title="Chrome only" alt="Chrome only" />
</a>
</li>
</ul>
</div>
@import "compass/css3";
$window-width: 800px;
$window-height: $window-width * 9/16; /* keep 16:9 ratio */
$glass-width: $window-width / 2;
$handle-width: 2px;
.wrapper {
width: 940px;
margin: 20px auto;
position: relative;
}
/*=== Title ===*/
hgroup {
text-align: center;
margin-bottom: 20px;
h1 {
font-size: 30px;
margin-bottom: 5px;
@include text-shadow(0px 1px 3px #999);
}
h3 {
font-weight: 300;
}
}
/*=== Main View ===*/
.window {
width: $window-width;
height: $window-height;
position: relative;
overflow: hidden;
float: left;
margin: 0 20px 20px 70px;
@include border-radius(5px);
@include box-shadow(0px 1px 2px 0px #999, inset 0px 1px 1px 0px white);
&.dragover {
animation: shake 0.5s infinite linear;
}
}
.glass {
width: $glass-width;
height: 100%;
position: absolute;
&.left {
left: 0px;
background-image: none;
background-size: $window-width;
background-position: top left;
@include border-top-left-radius(5px);
@include border-bottom-left-radius(5px);
}
&.right {
right: 0px;
background-image: none;
background-size: $window-width;
background-position: top right;
margin: -1px;
padding: 1px;
@include border-top-right-radius(8px); /* should be 5px, chrome overflow fix */
@include border-bottom-right-radius(5px);
}
}
.handle {
width: $handle-width;
height: 100%;
position: absolute;
background: gray;
z-index: 1;
cursor: pointer;
left: $glass-width - ($handle-width / 2);
&:after {
content: '‹ ›';
text-align: center;
font-family: serif;
font-size: 24px;
line-height: 26px;
display: block;
position: absolute;
width: 30px;
height: 30px;
border-radius: 100%;
top: 50%;
left: 50%;
margin: -15px 0 0 -15px;
background: #ddd;
@include box-shadow(0px 1px 1px 0px #222, inset 0px 1px 1px 0px white);
}
}
/*=== Filter Menu ===*/
.filter-choice {
float: left;
width: 50px;
height: $window-height;
position: relative;
> li {
width: 50px;
height: 28px;
margin-bottom: 10px;
position: relative;
@include border-radius(5px);
&.alt {
position: absolute;
bottom: 0;
text-align: center;
img:hover {
background: #999;
@include border-radius(100%);
@include box-shadow(0px 0px 1px 0px #999);
}
}
&:hover:after {
content: attr(data-filter);
display: block;
position: absolute;
width: 100px;
height: 100%;
line-height: 26px;
font-size: 12px;
top: 0;
left: 115%;
@include filter(none);
}
input {
display: block;
width: 50px;
height: 28px;
cursor: pointer;
margin: 0;
background-size: 100%;
background-repeat: no-repeat;
@include appearance(none);
@include border-radius(5px);
@include transition(box-shadow 0.2s);
@include box-shadow(0px 1px 2px 0px #999, inset 0px 1px 1px 0px white);
&:hover {
@include box-shadow(0px 1px 2px 1px #999, inset 0px 1px 1px 0px white);
}
&:active, &:checked {
@include box-shadow(inset 0px 1px 3px 1px #999, 0px 1px 1px 0px white);
}
}
}
}
/*=== Filter Classes ===*/
.filter-grayscale {
@include filter(grayscale(1));
}
.filter-sepia {
@include filter(sepia(1));
}
.filter-blur {
@include filter(blur(5px));
}
.filter-brightness {
@include filter(brightness(0.5));
}
.filter-contrast {
@include filter(contrast(10));
}
.filter-hue-rotate {
@include filter(hue-rotate(90deg));
}
.filter-invert {
@include filter(invert(1));
}
.filter-saturate {
@include filter(saturate(10));
}
input[type="radio"].filter-blur { /* blur filter fix for thumb */
@include filter(blur(1px));
}
/*=== Animations ===*/
@keyframes shake {
0% {
@include transform(rotate(0deg));
}
25% {
@include transform(rotate(2deg));
}
75% {
@include transform(rotate(-2deg));
}
100% {
@include transform(rotate(0deg));
}
}
body {
font-family: 'Open Sans', sans-serif;
background: #ddd;
background-image: url(http://kindofone.me/resources/gray_jean.png);
}
var imageWindow = $('.window');
var leftGlass = $('.glass.left');
var rightGlass = $('.glass.right');
var initialWidth = leftGlass.width();
// Drag and Drop event listeners
imageWindow.on('dragover', onDragOver);
imageWindow.on('dragenter', onDragEnter);
imageWindow.on('dragleave', onDragLeave);
imageWindow.on('drop', onDrop);
// Glass handle drag behavior
$('.handle').draggable({axis: 'x',
containment: 'parent',
drag: function(event, ui) {
var handleOffset = ui.position.left - initialWidth;
leftGlass.width(initialWidth + handleOffset);
rightGlass.width(initialWidth - handleOffset);
}
});
// Filter chooser events
$('input[name="filter-choice-group"]').on('click', function() {
// remove any previous filter-* class from right glass
rightGlass.removeClass(function (index, css) {
return (css.match (/\bfilter-\S+/g) || []).join(' ');
});
// add the selected filter class to the right glass
rightGlass.addClass('filter-' + $(this).val());
});
setImage('http://kindofone.me/resources/TheOtherSideOfManhattan.jpg');
function setImage(uri) {
$('.img').css('background-image', 'url('+uri+')');
}
// Drag And Drop event handlers
function onDragOver(evt) {
evt.stopPropagation();
evt.preventDefault();
evt.originalEvent.dataTransfer.dropEffect = 'copy';
}
function onDragEnter(evt) {
evt.stopPropagation();
evt.preventDefault();
$('.window').addClass('dragover');
}
function onDragLeave(evt) {
evt.stopPropagation();
evt.preventDefault();
$('.window').removeClass('dragover');
}
// Thanks Eric Bidelman :)
function onDrop(evt) {
evt.stopPropagation();
evt.preventDefault();
$('.window').removeClass('dragover');
// Allowed file types
var allowedFileTypes = /image.*/;
// Get dropped file object
var file = evt.originalEvent.dataTransfer.files[0];
// Validate allowed type, or break
if (!file.type.match(allowedFileTypes)) {
return;
}
// Setup FileReader
var reader = new FileReader();
reader.onerror = function(evt) {
console.log('FileReader error: ' + e.target.error);
}
reader.onload = (function(aFile) {
return function(evt) {
// Set dropped file as current image
setImage(evt.target.result);
}
})(file);
reader.readAsDataURL(file);
}
Also see: Tab Triggers