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.
<section id=s1>
<div>
<article>
<h1>Scroll Jacking with CSS</h1>
<p>Right now you are reading content inside of a fixed-position child of a relatively-positioned transparent area.</p>
<p>You are hovering over the transparent area (the white tint background) which is displaying this content. This fixed child content has a colored background image with a blend mode which appears to modify the original background image you saw before hover.</p>
<p>If you keep scrolling down you will see a line. If you hover beneath that line you will be hovering over the next section and it will make this content disappear.</p>
</article>
</div>
</section>
<section id=s2>
<div>
<article>
<h1>Changing Hover Areas</h1>
<p>You are now reading the second section's fixed content with a green background. This is because you are hovering over the second section (the white tint background).</p>
<p>If you didn't move your mouse and scrolled to get here, you may have noticed that the hover event doesn't fire until scrolling has completely stopped. This is default browser behavior.</p>
<p>This means you can quickly scroll to the bottom of the page and it will skip the sections along the way.</p>
</article>
</div>
</section>
<section id=s3>
<div>
<article>
<h1>Why This is Awesome</h1>
<p>As you can see, the result is pretty amazing for not using any Javascript. This goes to show you that CSS can do some pretty crazy things.</p>
</article>
</div>
</section>
<section id=s4>
<div>
<article>
<h1>Why This Sucks</h1>
<p>First off, you cant select this text because the "hover" section areas are sitting on top of it. This is because we need to hover event to make this work.</p>
<p>Secondly, this pen is useless if you aren't hovering over it, so you cant use this on a tablet or phone. Relying on hover is a terrible idea.</p>
</article>
</div>
</section>
<div class=default>
<h1>Hover if you know what's good for ya</h1>
</div>
<div class=bg></div>
// section count
$sections: 4;
// width of svgs
$svg-w: 200px;
// kind of like a throttle, increase to add more scrolling
$section-height: 100vh;
// easing
$cubic-enter: cubic-bezier(1, 1.6, 0.3, 1);
$cubic-leave: cubic-bezier(0.32,-0.24, 0.24, 0.98);
// colors
$c-light: #D7D7CE;
$c-dark: #2A2B26;
// body height
body {
position: relative; // needed to stretch body to bottom
}
section {
// sizing our sections
height: $section-height;
width: 100%;
box-sizing: border-box;
position: relative;
// subtle white on hover
&::after {
content: "";
position: absolute;
top: 0;
right: 0;
bottom: 0;
left: 0;
transition: background 250ms $cubic-leave;
z-index: 2;
}
&:hover {
// hide default message
~ .default {
opacity: 0;
visibility: hidden;
}
// show subtle white bg on section
&::after {
transition-timing-function: $cubic-enter;
background: rgba(#FFF,0.05);
}
}
// border reference between sections
+ section::before {
content: "";
position: absolute;
top: 0;
left: 0;
width: 100%;
z-index: 99;
border-top: 1px solid rgba(#FFF,0.2);
}
// different backgorund color tints for each
@for $i from 1 through $sections {
&:nth-of-type(#{$i}) {
div { background-color: hsl((($i - 1) / $sections * 360), 50%, 50%); }
}
}
// section content
// this is displayed fixed all the time,
// but only visible when hovering over static section
div {
position: fixed;
opacity: 0;
top: 0; left: 0; right: 0;
height: 100vh;
transition: opacity 250ms linear;
background-blend-mode: multiply;
}
article {
width: 95%;
max-width: 600px;
position: absolute;
left: 50%;
top: 50%;
padding: 1rem 2rem;
box-sizing: border-box;
background: rgba(#000,0.9);
box-shadow: 0px 1px 0px 2px rgba(#FFF,0.05);
border-radius: 2px;
transform: translateX(-50%) translateY(0%);
transition: transform 500ms $cubic-leave;
}
h1 {
margin-top: 1rem;
}
// show content on hover (when scrolling over it)
// scroll to a switchpoint
// move your mouse to top and then bottom of window
// it should change the content because you are hovering
// over a different section
&:hover > div {
opacity: 1;
article {
transform: translateX(-50%) translateY(-50%);
}
}
}
section > div,
div.bg {
// .bg is the default background behind everything
// section > div is for each section because they all need to mix with bg color for blend mode
background-image: url(//s3-us-west-2.amazonaws.com/s.cdpn.io/111863/image_dark_matter_example_1.jpg);
background-position: center;
background-size: cover;
}
div.default {
position: fixed;
width: 100%;
top: 50%;
transition: opacity 250ms;
}
div.bg {
position: fixed;
pointer-events: none;
top: 0; left: 0; right: 0;
height: 100vh;
background-blend-mode: multiply;
background-color: $c-dark;
z-index: -1;
}
// non essential style
body {
background-color: $c-dark;
color: $c-light;
}
h1 {
font-weight: 100;
width: 100%; text-align: center;
margin-top: 0;
}
p {
line-height: 1.6;
font-weight: 100;
}
Also see: Tab Triggers