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.
<a class="skip-link screen-reader-text" href="#content">Skip to content</a>
<header class="masthead">
<h1 class="site-title">Interactive Grid Gallery</h1>
<div class="intro">
<p>Interactive gallery using CSS Grid for both overall layout and individual card layout. This layout was inspired by the <a href="https://twitter.com/i/moments" target="_blank" rel="nofollow">Twitter Moments</a> page and showcases how CSS Grid allows for advanced responsive card-based layouts at multiple levels.</p>
<p>This example is based on one of the exercises from my upcoming <a href="https://lnkd.in/mor10" target="_blank" rel="nofollow">LinkedIn Learning</a> and <a href="https://lynda.com/mor10" target="_blank" rel="nofollow">Lynda.com</a> course "Advanced Layouts with CSS Grid."
</div>
</header><!-- .masthead -->
<main id="content" class="main-area">
<ul class="cards">
<li class="card-item double">
<a href="https://unsplash.com/@andozo?photo=crVO0UMdoVU" target="_blank" rel="nofollow">
<figure class="card">
<img src="https://source.unsplash.com/crVO0UMdoVU/600x600" alt="Beach. Photo by Andreas Rønningen">
<figcaption class="caption">
<h3 class="caption-title">Beach</h3>
<div class="location">Mølen, Nevlunghamn, Norway</div>
<p>This grid item spans one column and three rows to create focus. This is achieved by setting <code>grid-column: span 3;</code>.</p>
</figcaption>
</figure>
</a>
</li>
<li class="card-item">
<a href="https://unsplash.com/@andozo?photo=xkMArBuwK44" target="_blank" rel="nofollow">
<figure class="card">
<img src="https://source.unsplash.com/xkMArBuwK44/600x600" alt="Pyramid. Photo by Andreas Rønningen">
<figcaption class="caption">
<h3 class="caption-title">Louvre Museum Pyramid</h3>
<div class="location">Paris, France</div>
<p>This grid item spans one column and one row. The card contains its own grid which lays out the contents for consistent display.</p>
</figcaption>
</figure>
</a>
</li>
<li class="card-item">
<a href="https://unsplash.com/@andozo?photo=w3lQVmuK8fw" target="_blank" rel="nofollow">
<figure class="card">
<img src="https://source.unsplash.com/w3lQVmuK8fw/600x600" alt="Fox. Photo by Andreas Rønningen">
<figcaption class="caption">
<h3 class="caption-title">What Does the Fox Say?</h3>
<div class="location">Hovedøya, Norway</div>
<p>I was surprised to learn there are foxes on Hovedøya. Then again, there are rabbits, so it makes sense.</p>
</figcaption>
</figure>
</a>
</li>
<li class="card-item">
<a href="https://unsplash.com/@andozo?photo=lr81rOg-gys" target="_blank" rel="nofollow">
<figure class="card">
<img src="https://source.unsplash.com/lr81rOg-gys/600x600" alt="Owl. Photo by Andreas Rønningen">
<figcaption class="caption">
<h3 class="caption-title">Brown Barn Owl</h3>
<div class="location">Bamble, Norway</div>
<p>Unlike the fox, everyone knows what the owl says: "Did you do that?"</p>
</figcaption>
</figure>
</a>
</li>
<li class="card-item">
<a href="https://unsplash.com/@andozo?photo=KUfkX6gVwBU" target="_blank" rel="nofollow">
<figure class="card">
<img src="https://source.unsplash.com/KUfkX6gVwBU/600x600" alt="Oslo. Photo by Andreas Rønningen">
<figcaption class="caption">
<h3 class="caption-title">Little Oslo Is Its Own Planet</h3>
<div class="location">Oslo, Norway</div>
<p>All the streets are different nations, each block a continent.</p>
</figcaption>
</figure>
</a>
</li>
<li class="card-item double">
<a href="https://unsplash.com/@andozo?photo=8hRYTck6LBQ" target="_blank" rel="nofollow">
<figure class="card">
<img src="https://source.unsplash.com/8hRYTck6LBQ/600x600" alt="Sunset. Photo by Andreas Rønningen">
<figcaption class="caption">
<h3 class="caption-title">Sunset Lake</h3>
<div class="location">Somewhere, Earth</div>
</figcaption>
</figure>
</a>
</li>
<li class="card-item">
<a href="https://unsplash.com/@andozo?photo=i9FLJwYhVQs" target="_blank" rel="nofollow">
<figure class="card">
<img src="https://source.unsplash.com/i9FLJwYhVQs/600x600" alt="Lake. Photo by Andreas Rønningen">
<figcaption class="caption">
<h3 class="caption-title">Bonfire by the Lake</h3>
<div class="location">Øyungen, Norway</div>
<p>Low light over a lake as three friends warm themselves by the fire.</p>
</figcaption>
</figure>
</a>
</li>
<li class="card-item">
<a href="https://unsplash.com/@andozo?photo=5d2ETacuSgw" target="_blank" rel="nofollow">
<figure class="card">
<img src="https://source.unsplash.com/5d2ETacuSgw/600x600" alt="Jump. Photo by Andreas Rønningen">
<figcaption class="caption">
<h3 class="caption-title">Jumping</h3>
<div class="location">Geiranger, Norway</div>
<p>Jumping behind a fence overlooking the Geiranger fjord.</p>
</figcaption>
</figure>
</a>
</li>
<li class="card-item">
<a href="https://unsplash.com/@andozo?photo=vMRMYoLQzwo" target="_blank" rel="nofollow">
<figure class="card">
<img src="https://source.unsplash.com/vMRMYoLQzwo/600x600" alt="Oslo Fjord. Photo by Andreas Rønningen">
<figcaption class="caption">
<h3 class="caption-title">In the Bay</h3>
<div class="location">Oslo, Norway</div>
<p>Greeting the ships sailing in on a late summer evening.</p>
</figcaption>
</figure>
</a>
</li>
<li class="card-item">
<a href="https://unsplash.com/@andozo?photo=S2YssLw97l4" target="_blank" rel="nofollow">
<figure class="card">
<img src="https://source.unsplash.com/S2YssLw97l4/600x600" alt="Oslo Fjord. Photo by Andreas Rønningen">
<figcaption class="caption">
<h3 class="caption-title">Sparklers and Warm Souls</h3>
<div class="location">Porsgrunn, Norway</div>
<p>A couple enjoys the sparkles of warm friendship.</p>
</figcaption>
</figure>
</a>
</li>
</ul>
</main>
<footer class="colophon grid">
<aside>Content, layout, design: <a href="https://twitter.com/mor10" target="_blank" rel="nofollow">Morten Rand-Hendriksen</a>.</aside>
<aside>All photos: <a href="https://unsplash.com/@andozo" target="_blank" rel="nofollow">Andreas Rønningen</a>.</aside>
</footer>
/*--------------------------------------------------------------
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 */
}
/*--------------------------------------------------------------
General styling
--------------------------------------------------------------*/
body {
margin: 0;
font-family: 'Helvetica', 'Arial', sans-serif;
font-size: 100%;
font-size: 1.2em;
}
img {
display: block;
border: 0;
width: 100%;
height: auto;
}
code {
font: 15px Monaco, Consolas, "Andale Mono", "DejaVu Sans Mono", monospace;
font-weight: bold;
}
/* Header */
.masthead {
text-align: center;
border-bottom: 1px solid hsl(0, 0%, 90%);
}
.intro {
margin: 0 auto;
padding: 1em 1em 2em;
max-width: 50em;
font-size: 90%;
text-align: left;
line-height: 1.4em;
columns: 2;
column-gap: 2em;
}
.intro p {
margin: 0 0 1em;
}
/* Colophon section */
.colophon {
padding: 2em;
background: hsl(0, 0%, 10%);
color: white;
font-size: 90%;
text-align: center;
line-height: 1.8em;
}
.colophon a {
color: white;
}
.colophon a:hover,
.colophon a:focus {
border-bottom: 1px solid white;
}
/*--------------------------------------------------------------
Cards:
--------------------------------------------------------------*/
.cards {
max-width: 25em;
margin: 1em auto;
padding: 0;
list-style-type: none;
}
.cards a {
display: block;
margin-bottom: 1em;
text-decoration: none;
}
.caption {
padding: 1em;
font-size: 90%;
color: black;
}
.caption-title {
margin: 0;
font-size: 1.4em;
line-height: 1em;
}
.location {
padding: .5em 0;
color: hsl(0, 0%, 40%);
}
.caption p {
margin-top: .5em;
margin-bottom: 0;
line-height: 1.3em;
}
.cards a:focus .caption,
.cards a:hover .caption {
background: hsl(0, 0%, 97%);
}
/*--------------------------------------------------------------
CSS Grid layout for wider screens, when browser supports grid:
--------------------------------------------------------------*/
@supports (grid-area: auto) {
@media screen and (min-width: 27em) {
.cards {
margin: 0 auto;
padding: 1em;
}
.card-item,
.card-item a {
display: flex;
align-items: stretch;
width: 100%;
}
.cards a:focus,
.cards a:hover {
outline: 1px solid hsl(0, 0%, 80%);
}
.cards a:focus .caption,
.cards a:hover .caption {
background: white;
}
.card {
margin: .5em;
display: grid;
grid-template-columns: 8em auto;
overflow: hidden;
}
.card img {
/* height: 100%;
width: auto; */
}
.caption {
background: white;
}
}
@media screen and (min-width: 62em) {
.cards {
max-width: none;
margin: 1em 0;
padding: 0 1em;
display: grid;
grid-template-columns: repeat(auto-fit, 25em);
grid-gap: 1em;
justify-content: center;
}
.double {
grid-row: span 3;
}
.double .card {
display: block;
}
.double img {
height: calc( (100% / 3) * 2 + .5em);
}
}
}
Also see: Tab Triggers