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.
<h1>Flexbox Boot Camp</h1>
<h5>Your Mission:</h5>
<p>This codepen template is your sandbox to try out properties and see them applied to the demo below. Save or fork this template, edit the CSS properties, and then see your soldiers (flex-items) fall in line and follow your orders.</p>
<h2>Vanilla CSS Flexbox</h2>
<div class="flex-container">
<div class="flex-item soldier-3 rogue-flex-item">Soldier 3 <small>I want to lead!</small></div>
<div class="flex-item soldier-1">Soldier 1 <small>Yes sir!</small></div>
<div class="flex-item soldier-2">Soldier 2 <small>Ten hut!</small></div>
</div>
<!-- /.flex-container -->
<h2>Bootstrap 4 Flexbox Classes</h2>
<div class="flex-container d-flex flex-row justify-content-start flex-wrap">
<div class="flex-item soldier-3 order-sm-3">Soldier 3 <small>I want to lead!</small></div>
<div class="flex-item soldier-1 order-sm-1">Soldier 1 <small>Yes sir!</small></div>
<div class="flex-item soldier-2 order-sm-2">Soldier 2 <small>Ten hut!</small></div>
</div>
<!-- /.flex-container -->
<hr>
<h4>Notes: <a href="https://bootstrapcreative.com/resources/flexbox-cheat-sheet/" target="_blank">Responsive Flexbox Cheat Sheet</a></h4>
<h2>Flex Container <small>commanding officer</small></h2>
<ul>
<li>Flex layout gives the container the ability to alter its items' width/height (and order) to best fill the available space of the container.</li>
<li>The container has a main axis and cross axis which depends on the flex direction. Each axis has a start and end. For example, if you set the flex direction to column. The main axis is vertical and the cross axis is horizontal. If you set the flex direction to row, the main axis is horizontal and the cross axis is vertical.</li>
</ul>
<h2>Flex Items <small>soldiers</small></h2>
<ul>
<li>Flexbox items are like soldiers because they follow the orders given by their container. Just like soldiers listen to their commanding officer in battle.</li>
<li>By default, flex items all want to appear on the same line</li>
<li>Individual flexbox items or soldiers can be targeted with a unique class and property to override the orders given by their container. The example below uses the class <code>.rogue-flex-item</code> to make adjustments to only Soldier J in red.</li>
</ul>
.flex-container {
/*
Do you want the container to behave like a block on inline element?
The containers can act like block or inline elements. This demo has multiple flexbox containers so if you change this to inline-flex they will nudge up together like a list of images would.
display:
flex = makes the container act display block
inline-flex = makes the container act display inline
*/
display:flex;
/*
Do you want your main axis to be vertical or horizontal?
flex-direction:
row (default) = left to right
row-reverse = right to left
column = top to bottom
column = reverse = bottom to top
*/
flex-direction:row;
/*
How do you want the extra space to be distributed along the main axis?
justify-content:
flex-start (default) = items anchored to the start
flex-end = items anchored to the start
center = items centered
space-between = items evenly distributed in the line. First item in on the start and last item is at the end
space-around = start and end items are not to the edge but have 1 unit of space on each side
space-evenly = similar to space-around, except all space is the same
*/
justify-content:flex-start;
/*
How do you want the extra space of LINES of items to be distributed along the cross axis?
align-content:
flex-start = items anchored to the start
flex-end = items anchored to the end
center = items centered
space-between first line at the start of the container and the last one is at the end
space-around = lines are evenly distributed with equal space around each line
stretch (default) = lines stretch to take up the space that is left
*/
align-content:;
/*
How do you want the extra space between items to be distributed along the cross axis?
align-items:
flex-start = cross axis align items to start
flex-end = cross axis align items to end
center = cross axis align items center
baseline = align baselines
stretch (default) = stretch to fill the container
*/
align-items:;
/*
Do you want the items to wrap if they don't fit on one line?
by default, flex items will try to fit all the items onto one line.
flex-wrap:
nowrap (default) = all items will try to stay on one line
wrap = if items don't fit they will wrap and create a new line below
wrap-reverse = if items don't fit they will wrap and create a new line above
*/
flex-wrap:wrap;
/*
This is a shorthand flex-direction and flex-wrap properties,
flex-flow: <‘flex-direction’> || <‘flex-wrap’>
*/
}
@media (min-width: 575px) {
.rogue-flex-item {
/*
Do you want to change the order this item is listed?
order: <number>; default is 0 - like its relative position
*/
order:3;
/*
Do you want to have this item to take up more space than the other items?
flex-grow: <number>; default 0
*/
flex-grow:0;
/*
Do you want this item to take less space than the other items?
flex-shrink: <number>; default 1
*/
flex-shrink:1;
/*
Do you want to set the default size of this item before the other item sizes are set?
flex-basis:
<length> =
auto (default) =
*/
flex-basis:;
/*
Do you want to override the align-items value for this item?
align-self:
auto =
flex-start =
flex-end =
center =
baseline =
stretch (default or what is set in align-items on the container) =
*/
align-self:;
/*
This is the shorthand for flex-grow, flex-shrink and flex-basis combined.
flex: none | [ <'flex-grow'> <'flex-shrink'>? || <'flex-basis'> ]
*/
}
}
/* for demo purposes */
body {
margin:2rem;
background: radial-gradient(circle, #f1e1cb, #ddbe92);
color:#394730;
font-size:18px;
line-height:1.2;
}
li {margin-bottom:.5rem;}
h1 {
font-family: 'Black Ops One', cursive;
text-transform: uppercase;
color:#922122;
font-size:50px;
}
h2 {
font-family: 'Black Ops One', cursive;
text-transform: uppercase;
font-weight: bold;
font-size:24px;
}
small {
font-style: italic;
font-size:60%;
opacity:.6;
}
.rogue-flex-item, .order-sm-3 {
color:#922122;
}
.flex-container {
background:#394730;
border:10px solid #282f23;
}
.flex-item {
padding:1rem;
font-weight:bold;
background:rgba(255, 255, 255, .8);
border:5px solid #727b72;
text-align: center;
position:relative;
}
.flex-item small {
background:#fff;
padding:5px;
position:absolute;
top:0;
right:0;
}
.flex-item:before {
content:" ";
background:url('https://77784758994c4367a843b5378c104e06.production.codepen.plumbing/img/army-man.png') no-repeat;
background-size: 50px 50px;
margin:0 auto;
width:50px;
height:50px;
display: block;
}
a {
color:#922122;
}
Also see: Tab Triggers