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="grid">
<header class="grid-item flex-container">
<div class="flex-item logo-container">
<h1 class="logo">FLEX-<strong>HEADER</strong></h1>
</div>
<div class="flex-item social">
<div class="social__item">
<a target="_blank" href="https://twitter.com/matchboxhero10" class="social__icon--twitter"><i class="icon--twitter"></i></a>
</div>
<div class="social__item">
<a target="_blank" href="https://facebook.com" class="social__icon--facebook"><i class="icon--facebook"></i></a>
</div>
<div class="social__item">
<a target="_blank" href="https://www.linkedin.com/pub/steven-roberts/7a/707/409" class="social__icon--linkedin"><i class="icon--linkedin"></i></a>
</div>
<div class="social__item">
<a target="_blank" href="#" class="social__icon--rss"><i class="icon--rss"></i></a>
</div>
</div>
<div class="flex-item menu-button">
<button class="hamburger header__menu-button js-menu-button" type="button">
<span class="hamburger__box">
<span class="hamburger__inner"></span>
</span>
</button>
</div>
</header>
<article class="grid-item">
<h1>CSS Grid - The Holy Grail (of) Layout</h1>
<p>The idea here is to build the holy grail layout in Grid, but obviously it needs to be responsive. Incase you don't know the holy grail layout is a header, a left sidebar, content and right sidebar and then a footer. The code to accomplish this complex layout is pretty short and really easy to follow and understand, the syntax and new properties in Grid are not only simple but somehow elegant.</p>
<p>Just as a bonus, we've also got that much asked for feature of the footer being at the bottom of the viewport when the content isn't long enough to fill it.</p>
<p>As this demo is built using CSS Grid you may need to turn on the appropriate browser flag, until around March 2017 when most modern broswers will support it, yey! :)</p>
<h2>Chrome</h2>
<p><a href="chrome://flags/#enable-experimental-web-platform-features">chrome://flags/#enable-experimental-web-platform-features</a><br>
Enable experimental Web Platform features
</p>
<h2>Firefox</h2>
<p><a href="about:config">about:config</a><br>
Enable layout.css.grid.enabled
</p>
</article>
<aside class="grid-item left">
Aside Left
</aside>
<aside class="grid-item right">
Aside Right
</aside>
<footer class="grid-item">
Built with ♥
</footer>
</div>
//
// Define Grid Areas
//
header {
grid-area: header;
}
.left {
grid-area: left-sidebar;
}
.right {
grid-area: right-sidebar;
}
article {
grid-area: article;
}
footer {
grid-area: footer;
}
// Apply Grid display and define template areas
.grid {
display: grid;
min-height: 100vh;
height: 100vh; // Needed for chrome
grid-template-areas:
"header"
"article"
"left-sidebar"
"right-sidebar"
"footer"
;
grid-template-columns: 1fr;
@media (min-width: 540px) {
grid-template-areas:
"header header"
"left-sidebar article"
"right-sidebar right-sidebar"
"footer footer";
grid-template-columns: 1fr 2fr;
}
@media (min-width: 1200px) {
grid-template-areas:
"header header header"
"left-sidebar article right-sidebar"
"footer footer footer"
;
grid-template-columns: 1fr 3fr 1fr;
grid-template-rows:
minmax(min-content, max-content)
auto
minmax(min-content, max-content)
;
}
}
.grid-item {
padding: 24px;
}
/////
//
// FLEXBOX CODE FROM THE PREVIOUS TUTORIAL
//
/////
.flex-container {
display: flex;
flex-wrap: wrap;
justify-content: space-between;
align-items: center;
flex-direction: column;
text-align: center;
padding: 0;
@media (min-width:540px) {
flex-direction: row;
text-align: left;
}
}
.flex-item {
flex: 1 0 auto;
width: 100%;
padding: 12px;
@media (min-width:540px) {
width: auto;
&:nth-child(1) {
order: 2;
text-align: center;
}
&:nth-child(2) {
order: 3;
}
&:nth-child(2),
&:nth-child(3) {
flex: 0 0 auto;
}
}
}
/////
//
// General Styling Starts
//
/////
// Set variables for padding and spacing
$base-spacing-unit: 24px;
$half-spacing-unit: $base-spacing-unit / 2;
*, *:before, *:after {
box-sizing: border-box;
}
.body {
font-family: 'Dosis', sans-serif;
}
// Import icon font, I've used Entypo (http://entypo.com/)
@import url(http://weloveiconfonts.com/api/?family=entypo);
// General Styling to make it look okay
@import url('https://fonts.googleapis.com/css?family=Sansita:400,700|Ubuntu:400,700');
body {
font-family: "Ubuntu", sans-serif;
line-height: 1.6;
color: #333;
}
h1 {
margin-top: 0;
}
h2 {
font-size: 1.2em;
margin-bottom: $half-spacing-unit / 2;
}
* + h2 {
margin-top: $base-spacing-unit;
}
h2 + p {
margin-top: 0;
}
article p:first-of-type {
font-size: 1.1em;
}
header {
background-color: #1D1F20;
color: white;
}
.left {
background-color: #828282;
color: white;
}
.right {
background-color: #B5B5B5;
}
article {
background-color: #E3E3E3;
}
footer {
background-color: #1D1F20;
color: white;
}
.logo {
font-weight:400;
font-size: 1.8em;
margin: 0;
}
// Hamburger icon
.hamburger {
padding: $half-spacing-unit;
display: inline-block;
cursor: pointer;
background-color: transparent;
border: 0;
margin: 0;
&__box {
width: $base-spacing-unit * 1.75;
height: $base-spacing-unit;
display: inline-block;
position: relative;
}
&__inner {
display: block;
top: 50%;
}
&__inner,
&__inner:before,
&__inner:after {
width: $base-spacing-unit * 1.75;
height: 4px;
background-color: white;
border-radius: 4px;
position: absolute;
transition-property: transform;
transition-duration: 0.15s;
transition-timing-function: ease;
}
&__inner:before,&__inner:after {
content: "";
display: block;
}
&__inner:before {
top: -($half-spacing-unit);
}
&__inner:after {
bottom: -($half-spacing-unit);
}
}
// List of icon unicode symbols from the icon font
// and background colours for the icons
$icon-list: (
twitter "\F309" #32b9e7,
facebook "\F30C" #4b70ab,
linkedin "\F318" #0087be,
instagram "\F32D" #6291b2,
rss "\E73A" #FB7629,
);
// Each loop for creating the icon CSS
@each $icon, $unicode, $icon-background in $icon-list {
.icon--#{$icon} {
&::before {
content: $unicode;
}
}
.social__icon--#{$icon} {
background-color: $icon-background;
&:hover {
// Swap black for white to make the icons lighter on hover
background-color: mix(black, $icon-background, 15%);
}
}
}
// Basic icon style
.icon {
font-family: 'entypo';
speak: none;
font-style: normal;
font-weight: normal;
font-variant: normal;
text-transform: none;
line-height: 1;
// Better Font Rendering
-webkit-font-smoothing: antialiased;
-moz-osx-font-smoothing: grayscale;
}
// Extend icon to all other icons
[class^="icon--"] {
@extend .icon;
}
// Display icons next to each other
.social__item {
display: inline-block;
margin-right: $half-spacing-unit / 4;
}
// Icon background
.social__icon {
font-size: 1.4em;
color: white;
text-decoration: none;
border-radius:100%;
width: $base-spacing-unit * 2;
height: $base-spacing-unit * 2;
text-align: center;
// Vertical Centering
display: flex;
align-items: center;
justify-content: center;
}
// Extend social__icon to all other icons
[class^="social__icon"] {
@extend .social__icon;
}
Also see: Tab Triggers