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 URL's added here will be added as <link>
s in order, and before the CSS in the editor. If you link to another Pen, it will include the CSS from that Pen. If the preprocessor matches, it will attempt to combine them before processing.
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.
If the stylesheet 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 CSS 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.
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 Skypack, which makes packages from npm not only available on a CDN, but prepares them for native JavaScript ES6 import
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>
<p class="logo">Logo</p>
<!-- progress bar -->
<div class="progress-bar">
<!-- indicator -->
<div class="indicator"></div>
</div>
</header>
<main class="article">
<h1 class="title">
It was going to be a beautiful ride
</h1>
<section class="author">
<div class="author_img"></div>
<div class="author_detail">
<p>Chloe Hwang</p>
<p>Feb 6, 2019</p>
</div>
</section>
<section>
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed auctor mauris lobortis, blandit massa sed, ultrices est. Maecenas tristique, tellus quis ullamcorper vestibulum, ante diam auctor justo, et tempor quam massa et mi. Aliquam vestibulum eros a velit consectetur, non consequat augue viverra. Proin pharetra sem nunc. Proin in erat tortor. Aenean feugiat vitae nulla sed mattis. Nunc et tempor velit.</p>
<p>Integer aliquet tellus id risus maximus, eget aliquet urna commodo. Maecenas sodales hendrerit ex et scelerisque. Sed posuere nisl libero, vel blandit lacus tristique quis. Integer nunc nulla, egestas nec massa rutrum, aliquam ullamcorper est. Maecenas a mollis ligula. Integer odio ex, aliquet nec diam ac, interdum interdum dolor. Sed ac rutrum augue.</p>
<p>Integer ac pretium eros. Vivamus non neque venenatis, feugiat mi sit amet, rhoncus elit. Ut vitae lacus vulputate, feugiat libero ac, varius ex. Praesent sodales aliquet ligula. Vivamus feugiat velit porta, gravida massa eu, gravida nulla. Suspendisse ac nibh auctor, egestas felis eget, egestas enim. Donec ac porttitor quam. Nullam finibus ultricies nibh id rhoncus. Nam ac magna sit amet enim dictum faucibus.</p>
<p>Pellentesque sit amet ultrices dolor. Suspendisse vehicula metus quis ante varius, sed varius nisi porta. Nullam vitae ligula sit amet felis sagittis ullamcorper ac eu velit. Nullam at ex nulla. Morbi nec posuere nisi. Donec rhoncus, massa ac congue vehicula, lorem odio volutpat sapien, vitae rhoncus ante lectus non felis. Nullam non commodo urna, ut cursus diam. Donec a posuere tellus. Interdum et malesuada fames ac ante ipsum primis in faucibus. Aenean ut mauris eros. Fusce non vulputate velit, sit amet finibus diam. Morbi bibendum maximus elit, ac egestas dolor pulvinar ut. Aenean et tellus vitae mi egestas pretium quis non odio. Integer mollis metus id metus mollis dignissim. Fusce malesuada est ut lectus iaculis aliquam. Fusce at libero porttitor, semper arcu sit amet, blandit turpis.</p>
<p>Nullam laoreet, ligula in venenatis sollicitudin, quam dui vulputate lorem, ac sollicitudin leo diam et nisl. Sed facilisis leo a neque mollis, non posuere elit dapibus. Nullam non massa a felis accumsan molestie. Integer eget eros id mauris ullamcorper accumsan facilisis non est. Aenean id purus nibh. Nulla tincidunt magna nisi. Sed lobortis orci urna, nec dignissim elit eleifend sit amet. Nunc nibh sapien, porttitor in quam in, pharetra lacinia tellus. Curabitur ut est lobortis, rutrum tellus vel, efficitur arcu. In ornare consequat consectetur. Quisque ornare tempus metus, eget consequat turpis hendrerit sit amet. Class aptent taciti sociosqu ad litora torquent per conubia nostra, per inceptos himenaeos. Nullam vel sem tincidunt, dapibus magna eget, blandit nisl. Integer euismod aliquet ipsum, in pulvinar ipsum convallis at. Morbi tincidunt nisl eget ullamcorper ultricies.</p>
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed auctor mauris lobortis, blandit massa sed, ultrices est. Maecenas tristique, tellus quis ullamcorper vestibulum, ante diam auctor justo, et tempor quam massa et mi. Aliquam vestibulum eros a velit consectetur, non consequat augue viverra. Proin pharetra sem nunc. Proin in erat tortor. Aenean feugiat vitae nulla sed mattis. Nunc et tempor velit.</p>
<p>Integer ac pretium eros. Vivamus non neque venenatis, feugiat mi sit amet, rhoncus elit. Ut vitae lacus vulputate, feugiat libero ac, varius ex. Praesent sodales aliquet ligula. Vivamus feugiat velit porta, gravida massa eu, gravida nulla. Suspendisse ac nibh auctor, egestas felis eget, egestas enim. Donec ac porttitor quam. Nullam finibus ultricies nibh id rhoncus. Nam ac magna sit amet enim dictum faucibus.</p>
<p>Pellentesque sit amet ultrices dolor. Suspendisse vehicula metus quis ante varius, sed varius nisi porta. Nullam vitae ligula sit amet felis sagittis ullamcorper ac eu velit. Nullam at ex nulla. Morbi nec posuere nisi. Donec rhoncus, massa ac congue vehicula, lorem odio volutpat sapien, vitae rhoncus ante lectus non felis. Nullam non commodo urna, ut cursus diam. Donec a posuere tellus. Interdum et malesuada fames ac ante ipsum primis in faucibus. Aenean ut mauris eros. Fusce non vulputate velit, sit amet finibus diam. Morbi bibendum maximus elit, ac egestas dolor pulvinar ut. Aenean et tellus vitae mi egestas pretium quis non odio. Integer mollis metus id metus mollis dignissim. Fusce malesuada est ut lectus iaculis aliquam. Fusce at libero porttitor, semper arcu sit amet, blandit turpis.</p>
<p>Nullam laoreet, ligula in venenatis sollicitudin, quam dui vulputate lorem, ac sollicitudin leo diam et nisl. Sed facilisis leo a neque mollis, non posuere elit dapibus. Nullam non massa a felis accumsan molestie. Integer eget eros id mauris ullamcorper accumsan facilisis non est. Aenean id purus nibh. Nulla tincidunt magna nisi. Sed lobortis orci urna, nec dignissim elit eleifend sit amet. Nunc nibh sapien, porttitor in quam in, pharetra lacinia tellus. Curabitur ut est lobortis, rutrum tellus vel, efficitur arcu. In ornare consequat consectetur. Quisque ornare tempus metus, eget consequat turpis hendrerit sit amet. Class aptent taciti sociosqu ad litora torquent per conubia nostra, per inceptos himenaeos. Nullam vel sem tincidunt, dapibus magna eget, blandit nisl. Integer euismod aliquet ipsum, in pulvinar ipsum convallis at. Morbi tincidunt nisl eget ullamcorper ultricies.</p>
<p style="text-align: center;">* * *</p>
</section>
</main>
.progress-bar {
background: #dfeaff;
height: 10px;
}
.indicator {
background: #b0ccff;
height: inherit;
width: 0; /* start off at 0, to be changed by JS */
}
/****** Additional styling below ******/
* {
-moz-osx-font-smoothing: grayscale;
-webkit-font-smoothing: antialiased;
box-sizing: border-box;
font-smoothing: antialiased;
}
body {
font-family: "Noto Serif SC", Georgia, serif;
margin: 0;
overflow: hidden;
}
header {
box-shadow: 0 4px 12px 0 rgba(0,0,0,.05);
position: sticky;
top: 0;
}
.logo {
border: 1px solid #b0ccff;
display: inline-block;
font-family: Helvetica;
font-size: 12px;
letter-spacing: 0.2em;
margin: 0.5rem 50px;
padding: 0.5em 1em;
text-transform: uppercase;
}
.article {
height: calc(100vh - 53px);
overflow-y: scroll;
padding: 50px;
}
.article p {
line-height: 1.6;
}
.title {
font-size: 40px;
margin-top: 0;
}
.author {
display: flex;
}
.author_img {
background: url('https://bit.ly/2SfmYqM') center;
background-size: cover;
border-radius: 100%;
height: 50px;
margin-right: 1em;
width: 50px;
}
.author_detail p {
font-family: Helvetica, sans-serif;
font-size: 0.9rem;
font-weight: 300;
margin: 0;
}
let indicator = document.querySelector('.indicator')
let article = document.querySelector('.article')
article.addEventListener('scroll', function() {
// 1) Each time on scroll, recalculate the progress
let articleHeight = article.scrollHeight - article.clientHeight // scrollable height of article
let scrollPosition = article.scrollTop // how far we've scrolled from the top
let progress = scrollPosition / articleHeight // calculate progress
let progressPercentage = (progress * 100) + "%" // turn progress into a percentage
// 2) Set width to new progress
indicator.style.setProperty('width', progressPercentage)
})
Also see: Tab Triggers