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="wrapper">
<div class="news-item hero-item">
<div class="thumbnail">
<div class="image-wrapper">
<img src="https://s3-us-west-2.amazonaws.com/s.cdpn.io/53819/divinity-medium.png" alt="Divinity" class="responsive-img">
</div>
</div>
</div>
<div class="news-item standard-item">
<div class="thumbnail">
<div class="image-wrapper">
<img src="https://s3-us-west-2.amazonaws.com/s.cdpn.io/53819/re7-chris-large.jpg" alt="Resident Evil 7" class="responsive-img">
</div>
</div>
</div>
<div class="news-item standard-item">
<div class="thumbnail">
<div class="image-wrapper">
<img src="https://s3-us-west-2.amazonaws.com/s.cdpn.io/53819/bioshock-large.jpg" alt="Bioshock 2" class="responsive-img">
</div>
</div>
</div>
<div class="news-item standard-item">
<div class="thumbnail">
<div class="image-wrapper">
<img src="https://s3-us-west-2.amazonaws.com/s.cdpn.io/53819/lara-small.jpg" alt="Tomb Raider" class="responsive-img">
</div>
</div>
</div>
<div class="news-item standard-item">
<div class="thumbnail">
<div class="image-wrapper">
<img src="https://s3-us-west-2.amazonaws.com/s.cdpn.io/53819/dishonored-2-medium.jpg" alt="Dishonored 2" class="responsive-img">
</div>
</div>
</div>
<div class="news-item standard-item">
<div class="thumbnail">
<div class="image-wrapper">
<img src="https://s3-us-west-2.amazonaws.com/s.cdpn.io/53819/infinite-small.jpg" alt="Bioshock Infinite" class="responsive-img">
</div>
</div>
</div>
<div class="news-item standard-item">
<div class="thumbnail">
<div class="image-wrapper">
<img src="https://s3-us-west-2.amazonaws.com/s.cdpn.io/53819/trine-2-large.png" alt="Trine 2" class="responsive-img">
</div>
</div>
</div>
<div class="news-item standard-item">
<div class="thumbnail">
<div class="image-wrapper">
<img src="https://s3-us-west-2.amazonaws.com/s.cdpn.io/53819/trine-2-large.png" alt="Trine 2" class="responsive-img">
</div>
</div>
</div>
<div class="news-item standard-item">
<div class="thumbnail">
<div class="image-wrapper">
<img src="https://s3-us-west-2.amazonaws.com/s.cdpn.io/53819/wild-hunt-large.jpg" alt="Wild Hunt" class="responsive-img" />
</div>
</div>
</div>
</div>
* {
box-sizing: border-box;
position: relative;
}
body {
margin: 0 3px;
font-family: 'Lato', sans-serif;
}
img {
display: block;
object-fit: cover;
}
.wrapper {
max-width: 1440px;
margin: 5px auto;
font-size: 0; // inline-block hack
display: grid;
grid-gap: 3px;
grid-template-columns: repeat(2, 1fr);
grid-template-rows: repeat(4, 1fr);
grid-template-areas:
"hero med1"
"small1 small2"
"small3 small4"
"small5 small6";
@media (min-width: 728px) {
grid-template-columns: repeat(4, 1fr);
grid-template-rows: repeat(5, 1fr);
grid-template-areas:
"small1 small2 hero hero"
"med1 med1 hero hero"
"med1 med1 hero hero"
"small3 small4 small5 small6";
}
@media (min-width: 1100px) {
grid-template-columns: repeat(5, 1fr);
grid-template-rows: repeat(4, 1fr);
grid-template-areas:
"small1 small2 hero hero hero"
"med1 med1 hero hero hero"
"med1 med1 hero hero hero"
"small3 small4 small5 small6 small7";
}
}
.hero-item {
grid-area: hero;
}
.standard-item:nth-child(2) {
grid-area: med1;
}
.standard-item:nth-child(3) {
grid-area: small5;
}
.standard-item:nth-child(4) {
grid-area: small1;
}
.standard-item:nth-child(5) {
grid-area: small2;
}
.standard-item:nth-child(6) {
grid-area: small3;
}
.standard-item:nth-child(7) {
grid-area: small4;
}
.standard-item:nth-child(8) {
grid-area: small6;
}
.standard-item:nth-child(9) {
grid-area: small7;
display: none;
@media (min-width: 1100px) {
display: block;
}
}
/* Styles related to the thumbnails */
.responsive-img {
max-width: 100%;
height: auto;
width: 100%;
}
.caption {
padding: 16px;
}
.thumbnail {
color: #fff;
position: relative;
overflow: hidden;
}
.image-wrapper {
&:after {
background: -webkit-gradient(
linear,
left bottom,
left top,
color-stop(1, rgba(0,0,0,0.0)), /* Top */
color-stop(0, rgba(0,0,0,1.0)) /* Bottom */
);
bottom: 0;
content: "";
left: 0;
opacity: .5;
position: absolute;
right: 0;
top: 0;
z-index: 2;
}
}
.news-item {
display: inline-block; // display: inline-block for non supported browsers
vertical-align: top;
font-size: 16px;
padding: 2px;
position: relative;
}
// Classes under media queries will have a mix of percentage
// based width and grid columns. Grid code will be ignored for
// unsupported browsers and percentage is used. Percentage width
// will be overwritten by supported browsers when grid is used.
.hero-item,
.standard-item {
width: 50%;
@media (min-width: 728px) {
width: 25%;
}
}
/* For browsers with grid */
// Cleaner code and no more percentage based width
@supports (display: grid) {
.wrapper > *,
.standard-item:nth-child(4),
.standard-item:nth-child(5),
.standard-item:nth-child(6) {
margin: 0;
width: auto;
}
// ensure image extends to the entire grid height
.hero-item,
.standard-item:nth-child(2) {
.responsive-img,
.image-wrapper,
.thumbnail {
height: 100%;
}
.image-wrapper,
img {
position: absolute;
top: 0;
bottom: 0;
right: 0;
left: 0;
}
}
}
Also see: Tab Triggers