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.
%header
.container
%h1 Direction-aware hover effect
%p CSS & bits of JS
.container
%ul
- 12.times do
%li
%a{:href => "#", :class => "normal"}
%svg{:viewBox => "0 0 80 76", :x => "0px", :y => "0px"}
%g
%path{:d => "M 68.9708 24.8623 L 60.4554 2.3018 C 59.9641 0.7017 58.1628 -0.2583 56.5252 0.3817 L 1.9822 20.2222 C 0.3822 20.7022 -0.4179 22.6222 0.2222 24.2223 L 8.8624 47.7797 L 8.8624 35.1484 C 8.8624 29.5024 13.3425 24.8623 18.8857 24.8623 L 32.9442 24.8623 L 50.63 12.862 L 60.7829 24.8623 L 68.9708 24.8623 L 68.9708 24.8623 ZM 77.098 32.0625 L 18.8857 32.0625 C 17.2512 32.0625 16.0625 33.4511 16.0625 35.1484 L 16.0625 72.8491 C 16.0625 74.5477 17.2512 75.9375 18.8857 75.9375 L 77.098 75.9375 C 78.742 75.9375 79.9376 74.5477 79.9376 72.8491 L 79.9376 35.1484 C 79.9376 33.4511 78.742 32.0625 77.098 32.0625 L 77.098 32.0625 ZM 73.0626 68.0625 L 23.9375 68.0625 L 23.9375 61.0852 L 31.4704 43.7232 L 42.7696 57.6777 L 53.4138 46.8062 L 67.1695 41.9375 L 73.0626 55.0815 L 73.0626 68.0625 L 73.0626 68.0625 Z"}
.info
%h3 Single-origin coffee whatever
%p Williamsburg tofu polaroid, 90's Bushwick irony locavore ethnic meh messenger bag Truffaut jean shorts.
@import url(https://fonts.googleapis.com/css?family=Bree+Serif);
$duration: 300ms;
$timing-fn: ease;
$turquoise: #1ABC9C;
$wet-asphalt: #34495E;
$midnight-blue: #2C3E50;
$clouds: #ECF0F1;
/* the important bits */
li {
perspective: 400px;
}
.info {
// hide-initial-state
transform: rotate3d(1,0,0, 90deg);
width: 100%;
height: 100%;
padding: 20px;
position: absolute;
top: 0;
left: 0;
border-radius: 4px;
pointer-events: none;
background-color: transparentize($turquoise, .1);
}
.in-top .info {
transform-origin: 50% 0%;
animation: in-top $duration $timing-fn 0ms 1 forwards;
}
.in-right .info {
transform-origin: 100% 0%;
animation: in-right $duration $timing-fn 0ms 1 forwards;
}
.in-bottom .info {
transform-origin: 50% 100%;
animation: in-bottom $duration $timing-fn 0ms 1 forwards;
}
.in-left .info {
transform-origin: 0% 0%;
animation: in-left $duration $timing-fn 0ms 1 forwards;
}
.out-top .info {
transform-origin: 50% 0%;
animation: out-top $duration $timing-fn 0ms 1 forwards;
}
.out-right .info {
transform-origin: 100% 50%;
animation: out-right $duration $timing-fn 0ms 1 forwards;
}
.out-bottom .info {
transform-origin: 50% 100%;
animation: out-bottom $duration $timing-fn 0ms 1 forwards;
}
.out-left .info {
transform-origin: 0% 0%;
animation: out-left $duration $timing-fn 0ms 1 forwards;
}
@keyframes in-top {
from {transform: rotate3d(-1,0,0, 90deg)}
to {transform: rotate3d(0,0,0, 0deg)}}
@keyframes in-right {
from {transform: rotate3d(0,-1,0, 90deg)}
to {transform: rotate3d(0,0,0, 0deg)}}
@keyframes in-bottom {
from {transform: rotate3d(1,0,0, 90deg)}
to {transform: rotate3d(0,0,0, 0deg)}}
@keyframes in-left {
from {transform: rotate3d(0,1,0, 90deg)}
to {transform: rotate3d(0,0,0, 0deg)}}
@keyframes out-top {
from {transform: rotate3d(0,0,0, 0deg)}
to {transform: rotate3d(-1,0,0, 104deg)}}
@keyframes out-right {
from {transform: rotate3d(0,0,0, 0deg)}
to {transform: rotate3d(0,-1,0, 104deg)}}
@keyframes out-bottom {
from {transform: rotate3d(0,0,0, 0deg)}
to {transform: rotate3d(1,0,0, 104deg)}}
@keyframes out-left {
from {transform: rotate3d(0,0,0, 0deg)}
to {transform: rotate3d(0,1,0, 104deg)}}
/* you can ignore this ones */
ul {
padding: 0;
margin: 0 0 50px;
&:after {
content: "";
display: table;
clear: both;
}
}
li {
position: relative;
float: left;
width: 200px;
height: 200px;
margin: 5px;
padding: 0;
list-style: none;
a {
display: inline-block;
vertical-align: top;
text-decoration: none;
border-radius: 4px;
}
h3 {
margin: 0;
font-size: 16px;
color: transparentize(#fff, .1);
}
p {
font-size: 12px;
line-height: 1.5;
color: transparentize(#fff, .2);
}
.normal {
width: 100%;
height: 100%;
background-color: $clouds;
color: transparentize($wet-asphalt, .4);
box-shadow: inset 0 2px 20px darken($clouds, 2);
text-align: center;
font-size: 50px;
line-height: 200px;
svg {
pointer-events: none;
width: 50px;
path {
fill: transparentize($wet-asphalt, .8);
}
}
}
}
* {
box-sizing: border-box;
}
body {
background-color: #fff;
}
h1 {
margin: 0 auto 5px;
text-align: center;
}
h3 {
font-family: 'Bree Serif', serif;
}
.container {
width: 840px;
margin: 0 auto;
}
header {
font-family: 'Bree Serif', serif;
text-align: center;
margin: 50px 0 25px;
color: $wet-asphalt;
p {
margin: 0;
color: transparentize($wet-asphalt, .6);
}
}
// - Noel Delgado | @pixelia_me
const nodes = [].slice.call(document.querySelectorAll('li'), 0);
const directions = { 0: 'top', 1: 'right', 2: 'bottom', 3: 'left' };
const classNames = ['in', 'out'].map((p) => Object.values(directions).map((d) => `${p}-${d}`)).reduce((a, b) => a.concat(b));
const getDirectionKey = (ev, node) => {
const { width, height, top, left } = node.getBoundingClientRect();
const l = ev.pageX - (left + window.pageXOffset);
const t = ev.pageY - (top + window.pageYOffset);
const x = (l - (width/2) * (width > height ? (height/width) : 1));
const y = (t - (height/2) * (height > width ? (width/height) : 1));
return Math.round(Math.atan2(y, x) / 1.57079633 + 5) % 4;
}
class Item {
constructor(element) {
this.element = element;
this.element.addEventListener('mouseover', (ev) => this.update(ev, 'in'));
this.element.addEventListener('mouseout', (ev) => this.update(ev, 'out'));
}
update(ev, prefix) {
this.element.classList.remove(...classNames);
this.element.classList.add(`${prefix}-${directions[getDirectionKey(ev, this.element)]}`);
}
}
nodes.forEach(node => new Item(node));
Also see: Tab Triggers