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.
- var headerClass = 'header', colorBg = 'bg'
header(class="#{headerClass}")
nav
a(href="#") Item 1
a(href="#") Item 2
a(href="#") Item 3
a(href="#") Item 4
div(class='#{colorBg}')
.wrapper
.content
h1.title Lorem Ipsum
p.
Lorem ipsum dolor sit amet, consectetur adipisicing elit. Quaerat tempora, eveniet aperiam a consectetur, porro rerum voluptas molestiae omnis qui beatae. Sit unde aperiam iste minus dolores praesentium optio consectetur, magni voluptatum ex ut velit nam tenetur corporis omnis esse!
p.
Lorem ipsum dolor sit amet, consectetur adipisicing elit. Beatae nihil iure, illum aliquam doloremque similique nobis maxime eligendi accusamus sit veniam, facilis, illo deleniti ut nesciunt optio blanditiis, repudiandae reiciendis?
p.
Lorem ipsum dolor sit amet, consectetur adipisicing elit. Voluptas nihil beatae, voluptatem quo laudantium perspiciatis sed ex placeat. Alias odit praesentium aliquam quam similique qui.
p.
Lorem ipsum dolor sit amet, consectetur adipisicing elit. Quidem itaque nostrum doloremque fugit iure maiores beatae nesciunt tempora fuga. Quasi doloremque impedit fugiat harum laboriosam molestias cum ipsa, fugit laborum earum facilis possimus perferendis inventore in aut rerum porro veniam aspernatur reprehenderit dolore tempora, tempore nemo officiis. Inventore delectus in, vel quos, quod ducimus iure.
// Settings
$nav-height: 40px;
$link-color: white;
$nav-bg: #2A2A1E;
$colorBg: 'bg';
$header-image-url: 'https://goo.gl/jZh3X5';
$headerClass: 'header';
$header-bg-position: center;
// specific
.#{$headerClass}{
background:{
image: url(http://unsplash.it/1900?image=210);
size: cover;
position: $header-bg-position;
}
position: fixed;
top: 0;
left: 0;
width: 100%;
nav{
z-index: 10;
position: relative;
line-height: $nav-height;
a{
margin: 0 10px;
color: $link-color;
transition: .3s all ease;
&:first-of-type{
margin-left: 0;
}
&:last-of-type{
margin-right: 0;
}
&:hover{
opacity: .7;
}
}
}
.#{$colorBg}{
width: 100%;
height: 100%;
top: 0;
left: 0;
position: absolute;
background: $nav-bg;
}
}
// General
body{
font-size: 22px;
line-height: 1.3;
font-family: Roboto;
h1{
font-weight: bold;
font-size: 2.5em;
line-height: 2;
}
p{
margin-bottom: 10px;
}
a{
text-decoration: none;
}
}
nav{
max-width: 1300px;
margin: 0 auto;
}
.wrapper{
background: white;
.content{
max-width: 1300px;
margin: 0 auto;
padding: 30px 0;
}
p{
padding-bottom: 5px;
}
}
$(document).ready(function () {
'use strict';
// variables
var windowHeight = $(window).height(),
// setttings
colorBg = 'bg',
headerClass = 'header',
headerHeight = windowHeight * 0.6, // = 60vh
navHeight = 40, // no px here
// time savers
body = $('body'),
background = $('.'+headerClass + ' ' + '.'+colorBg),
header = $(headerClass);
/*
* set height of body to something big,
* so that scroll can happen
*/
body.css({
'min-height': windowHeight * 3
});
$(window).resize(function () {
// set header height and min-height
header.css({
'height': headerHeight,
'min-height': navHeight
});
// set body margin, so header does not overlap content
body.css({
'margin-top': headerHeight
});
// reduce opacity to see background image
background.css({ 'opacity': 0 });
$(window).scroll(function () {
var scrollTop = $(this).scrollTop(),
/*
* limit describes the point at
* which opacity should be 1
*/
limit = headerHeight - navHeight;
/*
* remove as many pixels as have been scrolled down,
* since min-height is set, the header will stop
* at a height of navHeight
*/
header.height(headerHeight - scrollTop);
/*
* increase opacity of colorBg
* until navbar is all saturated
*/
if (scrollTop <= limit) {
background.css({ 'opacity' : (scrollTop/limit) });
}
});
}).resize(); // trigger resize handles
});
Also see: Tab Triggers