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 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.
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<!--
The <meta> element below is important to help change the size of our browser window to reflect the size of the device. It works as follows:
name="viewport" - this clarifies that we are declaring something about the viewport (aka browser window)
'width=device-width' - this specifies that the width of the viewport should be equal to the width of our device (important for mobile devices)
'initial-scale=1' - this ensures that our website renders not zoomed-in or zoomed-out, as we have designed it to be responsive.
If you would like more information on why we set this, I recommend reading this article - https://developer.mozilla.org/en-US/docs/Mozilla/Mobile/Viewport_meta_tag
-->
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>My Less Hideous Page</title>
<link rel="stylesheet" href="css/normalize.css">
<link rel="stylesheet" href="css/grid.css">
<link rel="stylesheet" href="css/main.css">
<link rel="stylesheet" href="css/fonts.css">
</head>
<body>
<h1>My Less Hideous Page</h1>
<p>
A robot is a <em>dangerous</em>, often humanoid, autonomous being that will take over soon. We must be vigilant. We must be wary. We must prepare to stop the robots from taking over. Transformers are here and are real. Robots such as Honda's <abbr title="Advanced Step in Innovative Mobility">ASIMO</abbr> is proof of that. They walk, and soon enough they will also be able to talk and drive us around. That is dangerous.
</p>
<!--
We removed the .add-gutters class as it looks odd once we have docked our navigation to the top of the page.
-->
<nav class="nav-main grid four-column">
<a href="#robot" class="nav-main-item">See a Robot</a>
<a href="#comments" class="nav-main-item bg1">Comment on Robots</a>
<a href="https://en.wikipedia.org/wiki/Robot" class="nav-main-item bg2">Robots (Wikipedia)</a>
<a href="https://www.shutterstock.com/search/robots?search_source=base_keyword" class="nav-main-item bg3">Robot Photos</a>
</nav>
<section id="robot">
<h2>See a Robot</h2>
<div class="grid two-column add-gutters">
<!--
Note that we have added a class of 'caption-inside' to our figure tag to alter how the caption appears on this element.
-->
<figure class="caption-inside">
<img src="https://andrewh.ca/teaches/web_design_and_development/tutorials/04/explanation/img/robot.jpg" alt="A toy robot with a menacing expression" height="1600" width="1063">
<figcaption>Beware of robots like this.</figcaption>
</figure>
<div class="column">
<h3>Links about robots:</h3>
<ol>
<li>
<a href="https://en.wikipedia.org/wiki/Robot" target="_blank">Wikipedia on Robots</a>
</li>
<li>
<a href="https://www.shutterstock.com/search/robots?search_source=base_keyword" target="_blank">Photos of robots</a>
</li>
</ol>
</div>
</div>
<h3>The code of how robots deal with humans:</h3>
<code>
# Human protocol<br>
robot.see("human", function(seen) {<br>
seen.destroy();<br>
});<br>
</code>
<h3>What the robot does as a result:</h3>
<samp>EXTERMINATE! EXTERMINATE! EXTERMINATE!</samp>
</section>
<section id="comments">
<h2>Comment on Robots</h2>
<p><strong>Commenting is currently closed.</strong></p>
</section>
</body>
</html>
/* THIS IS WHAT WAS MODIFIED IN MAIN.CSS AS PART OF THE TUTORIAL */
/*
Because we already have an existing class for our navigation, we can just select it.
*/
.nav-main {
/*
Using the position property we can specify that we want this element to be positioned differently then the default 'static' positioning.
In this case, fixed positioning 'fixes' the element to the page while you scroll.
*/
position: fixed;
/*
Only once we set the positioning of an element to a value other then 'static' can we use the top, right, bottom, and left properties. These properties define the distance of the element along those edges depending on what kind of positioning is set.
In this case, we are making sure our 'fixed' element is positioned zero pixels from the top, left, and right edges.
*/
top: 0;
right: 0;
left: 0;
/*
Because elements that appear later on our page have a positioning set, we have to use the z-index property to ensure that our fixed navigation does not get overlapped by them when we scroll. Higher values for z-index indicate a higher layer.
*/
z-index: 10;
}
/*
By setting a positioning for the .caption-inside element - in this case a <figure> - we can ensure that its child elements - <img> and <figcaption> - stay within the bounds of their parent when being positioned.
Position relative without any top, right, bottom, and left properties remains in the same spot as a statically positioned element.
*/
.caption-inside {
position: relative;
}
/*
A reminder that a space between the two selectors below '.caption-inside' and 'figcaption' indicates only 'figcaptions' that are children of '.caption-inside' elements will be styled as specified
*/
.caption-inside figcaption {
/*
Positioning an element as 'absolute' sets it to be positioned absolutely to the last parent element with a positioning set (other then static).
As <figcaption> is the child of .caption-inside, which is positioned relative, <figcaption> is then positioned absolutely to .caption-inside based on the top, right, bottom, and left values set.
*/
position: absolute;
/*
By setting a bottom value of 0 we are placing the caption right at the bottom of the image.
*/
bottom: 0;
padding: 0.25rem 0.5rem;
/*
To help ensure that the content in our caption is readable, we can use a black background with some opacity and white text to increase the contrast.
*/
color: white;
background-color: rgba(0, 0, 0, 0.9);
/*
By setting the width to 100% we can have it span the full width of the image.
*/
width: 100%;
}
/*
This will fix the little space at the end of image elements because they are not 'block' level elements by default.
*/
img {
display: block;
}
/*
Because our navigation is now fixed and overlaps our content, we need to introduce some space at the top of our page to ensure that overlap doesn't occur. The simplest solution to this is to introduce 'padding-top' to the body element so all the content has some additional spacing (thereby avoiding the overlap).
*/
body {
padding-top: 8rem;
}
@media (min-width: 51.25rem) {
/*
Using the same selector in the media queries, we can adjust the padding-top for the body tag as the page resizes.
*/
body {
padding-top: 4rem;
}
}
@media (min-width: 70rem) {
/*
Using the same selector in the media queries, we can adjust the padding-top for the body tag as the page resizes.
*/
body {
padding-top: 2rem;
}
}
/* THIS IS IN GRIDS.CSS IN THE TUTORIAL FILES */
* {
box-sizing: border-box;
}
.grid {
display: grid;
}
.grid.add-gutters {
grid-column-gap: 1rem;
grid-row-gap: 0.25rem;
}
@media (min-width: 51.25rem) {
.grid.two-column, .grid.four-column {
grid-template-columns: 1fr 1fr;
grid-template-rows: auto;
grid-auto-flow: row;
}
}
@media (min-width: 70rem) {
.grid.four-column {
grid-template-columns: 1fr 1fr 1fr 1fr;
grid-template-rows: auto;
grid-auto-flow: row;
}
}
/* THIS IS IN MAIN.CSS IN THE TUTORIAL FILES */
body {
font-family: "Fira", Verdana, sans-serif;
margin: 1rem;
font-size: 1.25rem;
}
h1 {
font-size: 3rem;
margin-bottom: 0;
}
h2 {
font-size: 2.25rem;
margin-bottom: 0;
}
h3 {
font-size: 1.6rem;
margin-bottom: 0;
}
p, ol, ul {
max-width: 40rem;
}
img {
height: auto;
max-width: 100%;
border-width: 0.1rem;
border-style: solid;
border-color: black;
}
figure {
margin: 0;
}
figcaption {
font-style: italic;
}
a {
color: rgb(200,0,0);
transition-property: color;
transition-duration: 0.5s;
}
a:active, a:hover, a:focus {
color: rgb(50,0,0);
text-decoration: none;
}
code, samp {
display: block;
background-color: rgb(230,230,230);
padding: 0.5rem;
}
.nav-main-item {
display: inline-block;
color: white;
background-color: rgb(250,100,75);
font-size: 1.5rem;
padding: 0.25rem 0.5rem;
text-decoration: none;
transition-property: background-color;
transition-duration: 0.5s;
transition-timing-function: ease-out;
}
.nav-main-item:active, .nav-main-item:hover, .nav-main-item:focus {
color: white;
background-color: rgb(50,50,50);
}
.bg1 {
background-color: purple;
}
.bg2 {
background-color: green;
}
.bg3 {
background-color: blue;
}
Also see: Tab Triggers