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.
<h1>Style Property Concept</h1>
<section>
<div class="header">
<button id="tween-1">Play</button>
<div class="syntax">
<div>TWEEN 1 - Element Style</div>
<pre>TweenLite.to(target1, 1, { style: element1 });</pre>
</div>
</div>
<div class="demo">
<div id="element-1" class="element">element 1</div>
<div id="target-1" class="target">target 1</div>
</div>
</section>
<section>
<div class="header">
<button id="tween-2">Play</button>
<div class="syntax">
<div>TWEEN 2 - Blacklist Props</div>
<pre>TweenLite.to(target2, 1, { style: element2, filterStyle: "-=backgroundColor,height" });</pre>
</div>
</div>
<div class="demo">
<div id="element-2" class="element">element 2</div>
<div id="target-2" class="target">target 2</div>
</div>
</section>
<section>
<div class="header">
<button id="tween-3">Play</button>
<div class="syntax">
<div>TWEEN 3 - Whitelist Props</div>
<pre>TweenLite.to(target3, 1, { style: element3, filterStyle: "+=backgroundColor,height" });</pre>
</div>
</div>
<div class="demo">
<div id="element-3" class="element">element 3</div>
<div id="target-3" class="target">target 3</div>
</div>
</section>
<section>
<div class="header">
<button id="tween-4">Play</button>
<div class="syntax">
<div>TWEEN 4 - Overwrite Props</div>
<pre>TweenLite.to(target4, 1, { style: element4, backgroundColor: "#2e8b57", rotation: -90 });</pre>
</div>
</div>
<div class="demo">
<div id="element-4" class="element">element 4</div>
<div id="target-4" class="target">target 4</div>
</div>
</section>
<section>
<div class="header">
<button id="tween-5">Play</button>
<div class="syntax">
<div>TWEEN 5 - CSS Rule</div>
<pre>TweenLite.to(target5, 1, { style: ".rule-1" });</pre>
</div>
</div>
<div class="demo">
<div id="target-5" class="target">target 5</div>
<div class="rule-box">
<div>
.rule-1 {<br>
width: 225px;<br>
height: 75px;<br>
background-color: #2e8b57;<br>
}
</div>
</div>
</div>
</section>
<section>
<div class="header">
<button id="tween-6">Play</button>
<div class="syntax">
<div>TWEEN 6 - Multiple Styles</div>
<pre>TweenLite.to(target6, 1, { style: [element6, ".rule-1", ".rule-2"], filterStyle: "-=x,y,rotation" });</pre>
</div>
</div>
<div class="demo">
<div id="element-6" class="element">element 6</div>
<div id="target-6" class="target">target 6</div>
<div class="rule-box">
<div>
.rule-1 {<br>
width: 225px;<br>
height: 75px;<br>
background-color: #2e8b57;<br>
}
</div>
<div>
.rule-2 {<br>
width: 125px;<br>
height: 125px;<br>
opacity: 0.5<br>
}
</div>
</div>
</div>
</section>
body {
margin: 40px;
background-color: #eee;
}
*, *:before, *:after {
-moz-box-sizing: border-box;
-webkit-box-sizing: border-box;
box-sizing: border-box;
}
h1 {
margin-bottom: 40px;
}
button {
background-color: darkslateblue;
color: white;
padding: 12px 18px;
border: none;
box-shadow: 0 1px 4px 0 rgba(0, 0, 0, 0.3);
cursor: pointer;
}
button:focus {
outline: none;
}
section {
position: relative;
min-width: 1200px;
margin: 0 0 75px;
visibility: hidden;
}
.header {
display: flex;
flex-direction: row;
width: 100%;
align-items: center;
padding-bottom: 15px;
}
.syntax {
flex: 1;
margin-left: 15px;
}
.syntax div {
font-weight: bold;
font-size: 14px;
}
.syntax pre {
font-size: 14px;
margin: 4px 0 0;
}
.demo {
border: 1px solid rgba(0, 0, 0, 0.3);
position: relative;
height: 250px;
}
.target,
.element {
color: white;
position: absolute;
left: 0;
top: 0;
font-size: 14px;
display: flex;
align-items: center;
justify-content: center;
box-shadow: 0 1px 4px 0 rgba(0, 0, 0, 0.8);
border: 1px solid transparent;
outline: 1px solid transparent;
}
.target {
background-color: cornflowerblue;
z-index: 1;
width: 150px;
height: 150px;
}
.element {
width: 100px;
height: 100px;
background-color: mediumvioletred;
border-radius: 50%;
transform: rotate(90deg);
}
.rule-box {
display: flex;
display: inline-flex;
flex-direction: row;
}
.rule-box div {
font-family: monospace;
background-color: ghostwhite;
box-shadow: 0 1px 4px 0 rgba(0, 0, 0, 0.5);
margin-right: 8px;
padding: 10px;
}
.rule-1 {
width: 225px;
height: 75px;
background-color: #2e8b57;
}
.rule-2 {
width: 125px;
height: 125px;
opacity: 0.5;
}
TweenLite.set(".rule-box", { x: 525, y: 75 });
TweenLite.set(".element", { x: 400, y: 75 });
TweenLite.set(".target", { x: 15, y: 15 });
var cssStyle = CSSExtender();
var element1 = $("#element-1"),
element2 = $("#element-2"),
element3 = $("#element-3"),
element4 = $("#element-4"),
element6 = $("#element-6");
var target1 = $("#target-1"),
target2 = $("#target-2"),
target3 = $("#target-3"),
target4 = $("#target-4"),
target5 = $("#target-5"),
target6 = $("#target-6");
// Extend styles
var style1 = cssStyle.extend({
target: target1,
styles: element1
});
var style2 = cssStyle.extend({
target: target2,
styles: element2,
filter: "-=backgroundColor,height"
});
var style3 = cssStyle.extend({
target: target3,
styles: element3,
filter: "+=backgroundColor,height"
});
var style4 = cssStyle.extend({
target: target4,
styles: element4
});
var style5 = cssStyle.extend({
styles: ".rule-1"
});
var style6 = cssStyle.extend({
target: target6,
styles: [element6, ".rule-1", ".rule-2"],
filter: "-=x,y,rotation"
});
// Add a paused property to extended styles
var tween1 = TweenLite.to(target1, 1, _.assign(style1, { paused: true }));
var tween2 = TweenLite.to(target2, 1, _.assign(style2, { paused: true }));
var tween3 = TweenLite.to(target3, 1, _.assign(style3, { paused: true }));
var tween5 = TweenLite.to(target5, 1, _.assign(style5, { paused: true }));
var tween6 = TweenLite.to(target6, 1, _.assign(style6, { paused: true }));
var tween4 = TweenLite.to(target4, 1, _.assign(style4, {
backgroundColor: "#2e8b57",
rotation: -90,
paused: true
}));
$("#tween-1").click(() => tween1.restart());
$("#tween-2").click(() => tween2.restart());
$("#tween-3").click(() => tween3.restart());
$("#tween-4").click(() => tween4.restart());
$("#tween-5").click(() => tween5.restart());
$("#tween-6").click(() => tween6.restart());
// Make content visible
TweenLite.set($("section"), { autoAlpha: 1 });
// ========================================================================
// CSS EXTENDER
// ========================================================================
function CSSExtender() {
var camelNames = {};
var kebabNames = {};
var prefixNames = ["-webkit-", "-moz-", "-ms-"];
var removeNames = ["transform", "svg"];
createCaseNames();
return {
extend: extend
};
// Basic functionality to extend CSS styles. Ignores vendor
// prefixes, shorthand properties, and most transforms
function extend(config) {
var style = {};
var sources = _.isArray(config.styles) ? config.styles : [config.styles];
var target = getElement(config.target);
var listNames = getListNames(config.filter);
var blackList = listNames.blackList;
var whiteList = listNames.whiteList;
_.forEach(sources, source => {
var element = getElement(source);
element && !whiteList
? _.assign(style, getDifference(target, element))
: _.assign(style, getStyle(element || source, whiteList));
});
return _.omit(style, blackList);
}
// Gets the style of a rule or element and filters the result
// if a whiteList of names is provided
function getStyle(source, whiteList) {
var css, style = {};
if (_.isElement(source)) css = window.getComputedStyle(source);
if (_.isString(source)) css = CSSRulePlugin.getRule(source);
if (!(css instanceof CSSStyleDeclaration)) return {};
var length = whiteList ? whiteList.length : css.length;
_.times(length, i => {
var kebab = whiteList ? kebabNames[whiteList[i]] : css[i];
var camel = camelNames[kebab];
var value = css.getPropertyValue(kebab);
if (camel && value) style[camel] = value;
});
return style;
}
// Converts the filter string into white and black listed names
function getListNames(filter = "=") {
var list = filter.split("=");
var names = list[1].split(",");
return {
whiteList: list[0] === "+" ? names : null,
blackList: list[0] === "-" ? names.concat(removeNames) : removeNames
};
}
// Gets the different styles between two elements
function getDifference(element1, element2) {
if (!_.isElement(element1) || !_.isElement(element2)) return {};
TweenLite.set([element1, element2], { y: "+=0" });
var style = {};
var style1 = window.getComputedStyle(element1);
var style2 = window.getComputedStyle(element2);
var transform1 = element1._gsTransform;
var transform2 = element2._gsTransform;
// Find difference in GSAP transforms
var transforms = _.omit(transform2, (value, name) => transform1[name] === value);
// Find difference in CSS values
_.forOwn(camelNames, (camelCase, name) => {
var value1 = style1.getPropertyValue(name);
var value2 = style2.getPropertyValue(name);
if (value1 !== value2) style[camelCase] = value2;
});
return _.assign(style, transforms);
}
// Creates a list of CSS properties in camel and kebab case
function createCaseNames() {
var style = window.getComputedStyle(document.body);
_.times(style.length, i => {
var name = style[i];
var inList = _.some(prefixNames, prefix => _.includes(name, prefix));
if (!inList) camelNames[name] = _.camelCase(name);
});
kebabNames = _.invert(camelNames);
}
function getElement(value) {
if (!value) return undefined;
if (_.isElement(value)) return value;
if (value.jquery) return value[0];
return undefined;
}
}
Also see: Tab Triggers