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.
<!-- Gallery -->
<main id="js-gallery" role="main" class="gallery">
<section class="gallery__body">
<div id="js-poster" class="main__gallery-poster poster">
<div class="poster__content">
<header class="poster__header">
<h1 class="poster__header-title">Ausstellung<br />Eidgenössisches Kunststipendium<br />1970</h1>
</header>
<section class="poster__meta">
<ul>
<li>Malerei</li>
<li>Grafik</li>
<li>Bildhauerei</li>
<li>Architektur</li>
</ul>
<ul>
<li>Veranstaltet vom Eidgenössischen</li>
<li>Departement des Innern</li>
<li>in Verbindung mut der Stadt Zürich</li>
<li>im Helmhaus Zürich</li>
<li>21 Februar - 11 Marz 1970</li>
</ul>
<ul>
<li>Geoffnet</li>
<li>Taglich von 10 - 12 und 14 - 18 Uhr</li>
<li>Mittwoch auch von 20 - 22 Uhr</li>
<li>Montag geschinossen</li>
<li>Eintritt frei</li>
</ul>
</section>
<section class="poster__body">
<div></div>
<div></div>
<div></div>
<div></div>
<div></div>
<div></div>
<div></div>
<div></div>
<div></div>
<div></div>
<div></div>
<div></div>
<div></div>
<div></div>
<div></div>
<div></div>
</section>
</div>
<!-- .poster__content -->
</div>
<!-- .poster -->
</section>
<!-- .gallery__body -->
</main>
<!-- Gallery -->
/**
* Mixins
*/
@mixin pos ($position, $top: auto, $right: auto, $bottom: auto, $left: auto) {
position: $position;
top: $top;
right: $right;
bottom: $bottom;
left: $left;
}
@mixin center($width: null, $height: null) {
position: absolute;
top: 50%;
left: 50%;
@if not $width and not $height {
transform: translate(-50%, -50%);
} @else if $width and $height {
width: $width;
height: $height;
margin: -($width / 2) #{0 0} -($height / 2)
} @else if not $height {
margin-left: -($width / 2);
transform: translateY(-50%);
width: $width;
} @else {
margin-top: -($height / 2);
transform: translateX(-50%);
height: $height;
}
}
/**
* Variables
*/
// Colors
$primary-color: #FB1610;
$secondary-color: #FC4A2C;
$off-white: #EEE;
// Measurements
$base-unit: 8.3333333333%;
$circle-height: 24%;
$border-width: 4px;
// Animations
$timing: cubic-bezier(0.455, 0.030, 0.515, 0.955);
$duration: 1s;
/**
* Animations
*/
@keyframes mutate {
0% {
height: 0%;
}
100% {
height: 150%;
}
}
/**
* Base
*/
*,
*:after,
*:before {
box-sizing: border-box;
}
body {
font-family: "Helvetica Neue","Helvetica", sans-serif;
-webkit-font-smoothing: antialiased;
-moz-osx-font-smoothing: grayscale;
}
h1,
h2,
h3,
h4,
h5,
h6 {
font-weight: bold;
}
/**
* Gallery
*/
.gallery {
@include pos(absolute, 0, 0, 0, 0);
z-index: 1;
width: 100%;
height: 100%;
overflow: hidden;
opacity: 1;
transition: $duration opacity $timing;
background: $primary-color;
background: radial-gradient(ellipse at center, lighten($primary-color, 5%) 0%, $primary-color 100%);
&.fadeOut {
opacity: 0;
}
}
.gallery__body {
@include center();
transform-origin: center center;
}
/**
* Poster
*/
.poster {
@include center();
transform-origin: center center;
display: inline-block;
vertical-align: middle;
&:before,
&:after {
z-index: -1;
position: absolute;
content: "";
bottom: 15px;
left: 8px;
width: 50%;
top: 80%;
max-width: 300px;
background: #777;
box-shadow: 0 15px 10px rgba(#000,.5);
transform: rotate(-3deg);
}
&:after {
transform: rotate(3deg);
right: 8px;
left: auto;
}
}
.poster__content {
position: relative;
width: 500px;
height: 700px;
overflow: hidden;
background-color: $primary-color;
color: $off-white;
box-shadow: 0 1px 4px 2px rgba(#000,.2);
}
.poster__header {
margin: 0 0 0 25%;
padding: 1.5em 0 0;
font-size: .45em;
}
.poster__header-title {
margin: 0 0 .25em;
font-size: 21px;
line-height: 1;
}
.poster__meta {
margin: 0 0 0 25%;
font-size: 6px;
font-weight: bold;
letter-spacing: 0.05em;
line-height: 1.4;
ul {
float: left;
width: 33.3333%;
}
}
.poster__body {
@include pos(absolute, 30%, 0, 0, 0);
div {
position: relative;
overflow: hidden;
width: 25%;
height: 25%;
float: left;
&::before {
@include pos(absolute, 50%, auto, auto, 50%);
content: "";
width: 200%;
transform: translate3d(-50%,-50%,0) rotate(-45deg);
background-color: $secondary-color;
}
&:nth-child(1)::before {
animation: mutate 2s infinite alternate;
}
&:nth-child(2)::before {
animation: mutate 2s 0.125s infinite alternate;
}
&:nth-child(3)::before {
animation: mutate 2s 0.25s infinite alternate;
}
&:nth-child(4)::before {
animation: mutate 2s 0.375s infinite alternate;
}
&:nth-child(5)::before {
animation: mutate 2s 0.5s infinite alternate;
}
&:nth-child(6)::before {
animation: mutate 2s 0.625s infinite alternate;
}
&:nth-child(7)::before {
animation: mutate 2s 0.75s infinite alternate;
}
&:nth-child(8)::before {
animation: mutate 2s 0.875s infinite alternate;
}
&:nth-child(9)::before {
animation: mutate 2s 1s infinite alternate;
}
&:nth-child(10)::before {
animation: mutate 2s 1.125s infinite alternate;
}
&:nth-child(11)::before {
animation: mutate 2s 1.25s infinite alternate;
}
&:nth-child(12)::before {
animation: mutate 2s 1.375s infinite alternate;
}
&:nth-child(13)::before {
animation: mutate 2s 1.5s infinite alternate;
}
&:nth-child(14)::before {
animation: mutate 2s 1.625s infinite alternate;
}
&:nth-child(15)::before {
animation: mutate 2s 1.75s infinite alternate;
}
&:nth-child(16)::before {
animation: mutate 2s 1.875s infinite alternate;
}
}
}
(function(window, document, undefined) {
'use strict';
/**
* Selectors
*/
var body = document.body,
gallery = document.getElementById('js-gallery'),
galleryWidth = gallery.offsetWidth,
galleryHeight = gallery.offsetHeight,
poster = document.getElementById('js-poster'),
posterWidth = poster.offsetWidth,
posterHeight = poster.offsetHeight,
posterPadding = '50';
/**
* Prefixed requestAnimationFrame
*/
var requestAnimationFrame = window.requestAnimationFrame
|| window.webkitRequestAnimationFrame
|| window.mozRequestAnimationFrame
|| window.msRequestAnimationFrame
|| function(callback) {
return setTimeout(callback, 1000 / 60);
};
/**
* Methods
*/
var throttle = function(callback, limit) {
var wait = false;
return function() {
if (!wait) {
callback.call();
wait = true;
setTimeout(function() {
wait = false;
}, limit);
}
};
};
var resizePoster = function() {
// Define variable
var scale;
// Get values for poster dimensions
scale = Math.min(
galleryWidth / posterWidth,
galleryHeight / posterHeight
);
// Scale Poster for larger viewports
poster.style[Modernizr.prefixed('transform')] = 'translate(-50%, -50%) ' + 'scale(' + scale + ')';
// Sync operation with browser
requestAnimationFrame(resizePoster);
};
var onResize = throttle(function() {
// Set Gallery width
galleryWidth = gallery.offsetWidth - posterPadding;
// Set Gallery height
galleryHeight = gallery.offsetHeight - posterPadding;
// Sync operation with browser
requestAnimationFrame(resizePoster);
}, 100);
/**
* Events/APIs/init
*/
// Set Gallery width
galleryWidth = gallery.offsetWidth - posterPadding;
// Set Gallery height
galleryHeight = gallery.offsetHeight - posterPadding;
// Sync operation with browser
requestAnimationFrame(resizePoster);
// Listen for resize event
window.addEventListener('resize', onResize, false);
})(window, document);
Also see: Tab Triggers