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.
<div class="site">
<a class="skip-link screen-reader-text" href="#content">Skip to content</a>
<header class="masthead">
<div class="logo">GRID PILE</div>
<h2 class="site-title">Stacked CSS Grid Effect</h2>
</header><!-- .masthead -->
<main id="content" class="main-area">
<figure class="feature">
<img src="https://source.unsplash.com/w3lQVmuK8fw/1200x600" alt="Fox.">
</figure>
<section class="splash">
<div class="splash-content">
<h2 class="content-title">Magical content restructuring with CSS Grid stacks</h2>
<div class="splash-text">
<p>This example demonstrates how to reposition content in a view by stacking multiple grids on top of one another. The goal of the example is to retain a logical markup structure while still allowing content to be split up and positioned on the grid. Case in point: From a HTML semantics standpoint, the main area should come before the sidebar area, and both should live on the same level without extra wrappers. This demo shows how stacking two grids allows the sidebar items to appear as if they are placed on the same grid as the main content while they are in reality placed in a separate grid positioned within and superimposed on top of the original grid.</p>
<p>A detailed breakdown of this demo explaining the approach and how everything fits together can be found on <a href="https://www.linkedin.com/pulse/grid-pile-stacking-css-grids-impossible-layouts-rand-hendriksen">LinkedIn Pulse</a>.</p>
</div><!-- .splash-text -->
</div><!-- .splash-content -->
</section><!-- .splash -->
<section class="buckets">
<ul>
<li>
<img src="https://source.unsplash.com/KUfkX6gVwBU/600x400" alt="Fog over Oslo.">
<div class="bucket">
<h3 class="bucket-title">Grid is great</h3>
<p>CSS Grid is a two-dimensional layout tool. It is great for layout out content in a grid, and for laying out content in two dimensions.</p>
</div><!-- .bucket -->
</li>
<li>
<img src="https://source.unsplash.com/1jKjJjGgDG8/600x400" alt="Sunset over the Oslo fjord.">
<div class="bucket">
<h3 class="bucket-title">Flex is great too</h3>
<p>Grid is not always the right option for layuts. If for example you need to lay out a series of identical boxes like those you see here, Flex may be a better option.</p>
</div><!-- .bucket -->
</li>
</ul>
</section><!-- .buckets -->
<section class="more">
<div class="more-content">
<h2 class="content-title">Subgrid could be nice here</h2>
<p>The solution provided here is limited by the lack of support for subgrids. If subgrids were available, the solution would be more refined. That said, the lack of subgrid was what brought me to this solution, and it has practical applications well outside of the current demo. So maybe not having subgrid has opened the door to other more interesting opportunities?<p>
</div><!-- .more-content -->
</section><!-- .more -->
</main>
<aside class="sidebar">
<div class="twin">
<h2 class="content-title">First Sidebar Item</h2>
<p>This is the first of two sidebar sections. It appears as the first of two items in the sidebar <code>aside</code> element which is located after the <code>main</code> element in the HTML source order. On narrow screens it visually appears after the <code>main</code> element. On medium screens it appears at the top of the left-hand sidebar. On wide screens it appears at the top of the left-hand sidebar.</p>
</div>
<div class="twin">
<h2 class="content-title">Second Sidebar Item</h2>
<p>This is the second of two sidebar sections. It appears as the second of two items in the sidebar <code>aside</code> element which is located after the <code>main</code> element in the HTML source order. On narrow screens it visually appears after the first sidebar item. On medium screens it appears as the second item of the left-hand sidebar. On wide screens it appears at the top of the right-hand sidebar.</p>
<p>This is the second of two sidebar sections. It appears as the second of two items in the sidebar <code>aside</code> element which is located after the <code>main</code> element in the HTML source order. On narrow screens it visually appears after the first sidebar item. On medium screens it appears as the second item of the left-hand sidebar. On wide screens it appears at the top of the right-hand sidebar.</p>
<p>This is the second of two sidebar sections. It appears as the second of two items in the sidebar <code>aside</code> element which is located after the <code>main</code> element in the HTML source order. On narrow screens it visually appears after the first sidebar item. On medium screens it appears as the second item of the left-hand sidebar. On wide screens it appears at the top of the right-hand sidebar.</p>
<p>This is the second of two sidebar sections. It appears as the second of two items in the sidebar <code>aside</code> element which is located after the <code>main</code> element in the HTML source order. On narrow screens it visually appears after the first sidebar item. On medium screens it appears as the second item of the left-hand sidebar. On wide screens it appears at the top of the right-hand sidebar.</p>
<p>This is the second of two sidebar sections. It appears as the second of two items in the sidebar <code>aside</code> element which is located after the <code>main</code> element in the HTML source order. On narrow screens it visually appears after the first sidebar item. On medium screens it appears as the second item of the left-hand sidebar. On wide screens it appears at the top of the right-hand sidebar.</p>
<p>This is the second of two sidebar sections. It appears as the second of two items in the sidebar <code>aside</code> element which is located after the <code>main</code> element in the HTML source order. On narrow screens it visually appears after the first sidebar item. On medium screens it appears as the second item of the left-hand sidebar. On wide screens it appears at the top of the right-hand sidebar.</p>
</div>
</aside><!-- .sidebar -->
<footer class="colophon">
<aside>All photos: <a href="https://unsplash.com/@andozo" target="_blank" rel="nofollow">Andreas Rønningen</a>.</aside>
<aside>Content, layout, design: <a href="https://twitter.com/mor10" target="_blank" rel="nofollow">Morten Rand-Hendriksen</a>.</aside>
</footer>
</div><!-- .site -->
/*--------------------------------------------------------------
Accessibility
--------------------------------------------------------------*/
/* Text meant only for screen readers */
.screen-reader-text {
clip: rect(1px, 1px, 1px, 1px);
position: absolute !important;
height: 1px;
width: 1px;
overflow: hidden;
}
.screen-reader-text:hover,
.screen-reader-text:active,
.screen-reader-text:focus {
background-color: #f1f1f1;
border-radius: 3px;
box-shadow: 0 0 2px 2px rgba(0, 0, 0, 0.6);
clip: auto !important;
color: #21759b;
display: block;
font-size: 14px;
font-weight: bold;
height: auto;
left: 5px;
line-height: normal;
padding: 15px 23px 14px;
text-decoration: none;
top: 5px;
width: auto;
z-index: 100000; /* Above WP toolbar */
}
/*--------------------------------------------------------------
Typography
--------------------------------------------------------------*/
body {
margin: 0;
font-family: 'Source Sans Pro', 'Helvetica', 'Arial', sans-serif;
font-size: 18px;
line-height: 1.5;
}
p {
margin-bottom: 1.5em;
}
b,
strong {
font-weight: bold;
}
em,
i {
font-style: italic;
}
figure {
margin: 0;
padding: 0;
}
/*--------------------------------------------------------------
General styling
--------------------------------------------------------------*/
h1,
h2,
h3 {
text-align: center;
margin: 0;
padding: 1em 0;
}
p {
margin: 0;
padding: 1em 0;
}
img {
display: block;
border: 0;
width: 100%;
height: auto;
}
/* Promo section */
.logo,
.site-title {
text-align: center;
}
.logo {
margin-top: .3em;
font-size: 6em;
}
.site-title {
margin-top: -1em;
margin-bottom: 2em;
}
/* Splash section */
.splash {
background: #FFF6E5;
padding-bottom: 2em;
}
.splash-content {
padding: 1.5em;
}
@media screen and (min-width: 600px) {
.splash-text {
columns: 2;
column-gap: 2em;
}
.splash-text p {
padding-top: 0;
}
}
/* Buckets section */
.buckets {
padding: 2em 1em 1em;
background: #3E454C;
}
.buckets ul {
margin: 0;
padding: 0;
}
.buckets li {
margin-bottom: 1em;
background: white;
list-style-type: none;
}
.bucket {
padding: 1.5em;
}
/* More section */
.more {
padding: 2em;
}
.more-content {
padding: 1.5em;
}
/* Twins section */
.sidebar {
background: hsl(0, 0%, 90%);
}
.twin {
padding: 2em;
background: #2185C5;
color: white;
}
.twin:last-of-type {
background: #FF7F66;
}
.content-title {
padding: .5em;
}
/* Colophon section */
.colophon {
padding: 2em;
background: hsl(0, 0%, 10%);
color: white;
text-align: center;
}
.colophon a {
color: white;
}
.colophon a:hover,
.colophon a:focus {
border-bottom: 1px solid white;
}
/*--------------------------------------------------------------
Use flex to create a three-bucket layout
--------------------------------------------------------------*/
@media screen and (min-width: 700px) {
@supports (display: flex) {
.buckets ul {
display: flex;
justify-content: space-around;
}
.buckets li {
width: 48%;
}
}
}
/*--------------------------------------------------------------
Basic responsive layout for all browsers:
--------------------------------------------------------------*/
.site {
max-width: 50em;
margin: 0 auto;
}
/*--------------------------------------------------------------
CSS Grid layout for modern browsers:
--------------------------------------------------------------*/
@supports (grid-area: auto) {
@media screen and (min-width: 50em) {
.site {
max-width: none;
display: grid;
grid-template-columns: 15em auto;
}
.masthead {
grid-column: 1/3;
}
.main-area {
grid-column: 2/3;
}
.sidebar {
grid-column: 1/2;
grid-row: 2/4;
}
.colophon {
grid-column: 1/3;
}
}
@media screen and (min-width: 65em) {
.site {
grid-template-columns: 15em auto 15em;
}
.masthead {
grid-column: 1/4;
}
.sidebar {
display: inherit;
grid-template-columns: inherit;
grid-column: 1/4;
grid-row: 2/3;
}
.twin:last-of-type {
grid-column: 3/4;
}
.main-area {
grid-row: 2;
z-index: 1;
}
.colophon {
grid-column: 1/4;
}
}
}
Also see: Tab Triggers