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 URL's added here will be added as <link>
s in order, and before the CSS in the editor. If you link to another Pen, it will include the CSS from that Pen. If the preprocessor matches, it will attempt to combine them before processing.
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.
If the stylesheet 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 CSS 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.
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.
<div class="container">
<div class="card card-1">
<div class="card-header">
1st card
</div>
<div class="card-body">
Meatloaf cupim drumstick, pig swine kielbasa frankfurter jerky pastrami ball tip bacon short ribs kevin. Fatback tri-tip kielbasa andouille, turkey hamburger rump beef ball tip swine filet mignon boudin frankfurter flank. Meatloaf sausage prosciutto, hamburger flank ribeye tenderloin turkey chuck.
</div>
</div>
<div class="card card-2">
<div class="card-header">
2nd card
</div>
<div class="card-body">
Bacon ipsum dolor amet chuck jerky alcatra shoulder meatball cupim corned beef boudin sirloin beef ribs pork chop ham pancetta swine meatloaf. Tongue pancetta filet mignon t-bone, bacon turkey ham short ribs. Short loin filet mignon flank, swine strip steak kevin cow pastrami. Meatloaf cupim drumstick, pig swine kielbasa frankfurter jerky pastrami ball tip bacon short ribs kevin. Fatback tri-tip kielbasa andouille, turkey hamburger rump beef ball tip swine filet mignon boudin frankfurter flank. Meatloaf sausage prosciutto, hamburger flank ribeye tenderloin turkey chuck.
</div>
</div>
<div class="card card-3">
<div class="card-header">
3rd card
</div>
<div class="card-body">
Lorem ipsum dolor sit amet, consectetur adipisicing elit. Voluptatibus consectetur dolor labore minima quos iure, voluptate voluptatum a voluptas non cupiditate unde fugit mollitia itaque ipsam eum excepturi est eius.
</div>
</div>
<div class="card card-4 flex-grow flex-align-self">
<div class="card-header">
last card
</div>
<div class="card-body">
Lorem ipsum dolor sit amet, consectetur adipisicing elit. Voluptatibus consectetur dolor labore minima quos iure.
</div>
</div>
</div>
// a code summary of this great post:
// https://css-tricks.com/snippets/css/a-guide-to-flexbox/
////////////////////////////
// the flex container:
///////////////////////////
.container {
// 1. context: this kickstarts a flex context for its direct children: the items
display:flex; /* or inline-flex for inline containers*/
// 2. flex-direction: the horizontal direction of the items: left to right, right to left, column, column reverse.
// 2. flex-direction: row | row-reverse | column | column-reverse;
flex-direction:row;
// 3. flex-wrap: nowrap | wrap | wrap-reverse;
// flex items will all try to fit onto one line. You can change that
// if you use wrap, the items need a declared width or min/max-width
flex-wrap: wrap;
// these last two's shorthand is:
//flex-flow: <‘flex-direction’> || <‘flex-wrap’>
flex-flow: row wrap;
// IMPORTANT! the following values have inverted behaviour depending on the flex direction: row or column.
// 3. justify-content: extra free horizontal space? decide how to distribute it. this has sense with pixel widths of the items or with widths/min/max-widths that don't totally cover the container
// justify-content: flex-start | flex-end | center | space-between | space-around;
justify-content: space-between;
// 4. align-items: extra vertical space between the flex children? manage how to align them.
//align-items: flex-start | flex-end | center | baseline | stretch;
align-items: stretch;
// 5. align-content: when the container has an height, this aligns ALL the items vertically, as if they were a single block: top, bottom, center etc. toggle the next two comments to see it in action
// align-content: flex-start | flex-end | center | baseline | stretch;
// height:100%;
// align-content: stretch;
}
////////////////////////////
// the flex items:
///////////////////////////
.card {
// 1. flex grow: This defines the ability for a flex item to grow horizontally if necessary. It accepts a unitless value that serves as a proportion. It dictates what amount of the available space inside the flex container the item should take up. If all items have flex-grow set to 1, the remaining space in the container will be distributed equally to all children. If one of the children has a value of 2, the remaining space would take up twice as much space as the others
flex-grow: 0; // default!
// 2. flex-basis: This defines the default size of an element before the remaining space is distributed. can substitute the "width"
flex-basis: 32%;
// 3. flex-shrink: it's like flex-grow but for vertical space
// flex-shrink: 1; // default!
flex-shrink:0;
// 4. the shorthand for these last 3 values: flex: none | <'flex-grow'> <'flex-shrink'>? || <'flex-basis'> - It is recommended that you use this shorthand property rather than set the individual properties. The short hand sets the other values intelligently.
flex: 0 0 32%;
&.flex-grow {
//the last card
flex-grow:0.5;
}
&.flex-align-self {
// 5. align-self: auto | flex-start | flex-end | center | baseline | stretch;
//This allows the default alignment (or the one specified by align-items) to be overridden for individual flex items. this works when the flex container has an height. It's about VERTICAL remaining space only. to move an item horizontally use margins
//align-self:center;
margin:auto;
}
}
// items order:
// order: number;
// you can specify the order of each children, despite their position in the DOM. uncomment to see it in action:
/*
.card-1 {
order:4;
}*/
/*
.card-2 {
order:3;
}*/
/*
.card-3 {
order:2;
}*/
/*
.card-4 {
order:1;
}*/
/* =================================================================== */
/* =================================================================== */
// resources + nice to know
/* =================================================================== */
/* =================================================================== */
// common flexbugs and workarounds: https://github.com/philipwalton/flexbugs
// common flexbugs solving automated: https://github.com/luisrudge/postcss-flexbugs-fixes
// use autoprefixer when working with flexbox to make your life easier with previous flexbox implementations
// this article is great: https://hackernoon.com/11-things-i-learned-reading-the-flexbox-spec-5f0c799c776b
// this answer is great: https://stackoverflow.com/questions/42613359/how-does-flex-wrap-work-with-align-self-align-items-and-align-content
// understanding flexbox with gifs: https://medium.freecodecamp.com/an-animated-guide-to-flexbox-d280cf6afc35
// remember that: a flex item can also be a flex container!
/* =================================================================== */
/* =================================================================== */
// cosmetic demo styles
/* =================================================================== */
/* =================================================================== */
* {
box-sizing:border-box;
}
html,body {
height: 100%;
}
body {
background: #999;
}
.container {
max-width: 1024px;
margin: 0 auto;
padding: 20px 0;
}
.card {
background: #fff;
box-shadow:0 0 10px rgba(0,0,0,.5);
padding: 20px;
margin-bottom: 2%;
}
.card-header {
border-bottom: 1px solid #eee;
padding-bottom: 10px;
margin-bottom: 10px;
font-size:24px;
line-height: 1.5;
text-transform: uppercase;
font-weight: bold;
}
Also see: Tab Triggers