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. You can use the CSS from another Pen by using it's URL and the proper URL extention.
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 The 4 Grid Techniques
.perimeter__float
h2 Floating Grid (Classic)
p.description This grid uses "floats" to create it's columns. Since floats don't have layout, you need something to force them to encapsulate thier contents. This is commonly fixed by using a "ClearFix" (which ironicaly uses "display: table-cell"). However, I just used "overflow: hidden." This is a classic grid solution. Columns always align to the top of their container, and the column is only as tall as it's content.
.container
.col-6-12
.content
p Bushwick fanny pack high life wolf single-origin coffee american apparel, cred twee gluten-free mixtape mlkshk ethical carles Austin direct trade. Etsy banksy biodiesel ethnic, cardigan chambray lomo four loko single-origin coffee. Wes anderson dreamcatcher chillwave whatever, before they sold out master cleanse polaroid fixie skateboard yr.
.col-6-12
.content
p Mcsweeney's PBR typewriter banksy wes anderson helvetica. Synth sriracha salvia, selvage pour-over 3 wolf moon 8-bit cosby sweater street art swag. Artisan echo park shoreditch, semiotics iphone dreamcatcher farm-to-table pinterest flexitarian cred ennui irony bicycle rights. Narwhal whatever etsy retro, kogi yr salvia fixie pork belly master cleanse wolf ethical PBR VHS.
.container
.col-4-12
.content
p Bushwick fanny pack high life wolf single-origin coffee american apparel, cred twee gluten-free mixtape mlkshk ethical carles Austin direct trade.
.col-4-12
.content
p Bushwick fanny pack high life wolf single-origin coffee american apparel.
.col-4-12
.content
p Bushwick fanny pack high life wolf single-origin coffee american apparel, cred twee gluten-free mixtape mlkshk ethical carles Austin direct trade.
.perimeter__inline-block
h2 Inline-block Grid
p.description
| This grid uses "inline-blocks" to create it's columns. The columns are set to "display: inline-block" and their parent can use "text-align" to position the inline elements. This technique was mostly used for achieving horizontal navigation without using floats. This works great however, 4px of margin gets added to each inline-block. You need to <a href="https://css-tricks.com/fighting-the-space-between-inline-block-elements/"> correct</a> this by using "margin-right: -4px." Columns align to the bottom of their container, however you can use vertical alignment to position them. It's columns are only as tall as it's content also.
.col-6-12
.content
p Bushwick fanny pack high life wolf single-origin coffee american apparel, cred twee gluten-free mixtape mlkshk ethical carles Austin direct trade. Etsy banksy biodiesel ethnic, cardigan chambray lomo four loko single-origin coffee. Wes anderson dreamcatcher chillwave whatever, before they sold out master cleanse polaroid fixie skateboard yr.
.col-6-12
.content
p Mcsweeney's PBR typewriter banksy wes anderson helvetica. Synth sriracha salvia, selvage pour-over 3 wolf moon 8-bit cosby sweater street art swag. Artisan echo park shoreditch, semiotics iphone dreamcatcher farm-to-table pinterest flexitarian cred ennui irony bicycle rights. Narwhal whatever etsy retro, kogi yr salvia fixie pork belly master cleanse wolf ethical PBR VHS.
.container
.col-4-12
.content
p Bushwick fanny pack high life wolf single-origin coffee american apparel, cred twee gluten-free mixtape mlkshk ethical carles Austin direct trade.
.col-4-12
.content
p Bushwick fanny pack high life wolf single-origin coffee american apparel.
.col-4-12
.content
p Bushwick fanny pack high life wolf single-origin coffee american apparel, cred twee gluten-free mixtape mlkshk ethical carles Austin direct trade.
.perimeter__table-cell
h2 Table-cell Grid
p.description This grid uses "table-cell" to create it's columns. The columns are set to "display: table-cell" and their parent is set to "table." Table-cells fill their rows completely, so you don't get potholes in your rows like you do with Floats and Inline-Blocks. This technique works like a charm, but everyone freaks out about using table behavior in CSS. This behavior is so good, that the "clearfix" to correct floating grids is based off of it! The content of a table-cell can be vertically positioned as well by using "vertical-align: [top, middle, bottom]."
.container
.col-6-12
.content
p Bushwick fanny pack high life wolf single-origin coffee american apparel, cred twee gluten-free mixtape mlkshk ethical carles Austin direct trade. Etsy banksy biodiesel ethnic, cardigan chambray lomo four loko single-origin coffee. Wes anderson dreamcatcher chillwave whatever, before they sold out master cleanse polaroid fixie skateboard yr.
.col-6-12
.content
p Mcsweeney's PBR typewriter banksy wes anderson helvetica. Synth sriracha salvia, selvage pour-over 3 wolf moon 8-bit cosby sweater street art swag. Artisan echo park shoreditch, semiotics iphone dreamcatcher farm-to-table pinterest flexitarian cred ennui irony bicycle rights. Narwhal whatever etsy retro, kogi yr salvia fixie pork belly master cleanse wolf ethical PBR VHS.
.container
.col-4-12
.content
p Bushwick fanny pack high life wolf single-origin coffee american apparel, cred twee gluten-free mixtape mlkshk ethical carles Austin direct trade.
.col-4-12
.content
p Bushwick fanny pack high life wolf single-origin coffee american apparel.
.col-4-12
.content
p Bushwick fanny pack high life wolf single-origin coffee american apparel, cred twee gluten-free mixtape mlkshk ethical carles Austin direct trade.
.perimeter__flex
h2 FlexBox Grid
p.description This grid uses "Flexbox" to create it's columns. The parent element holding the columns is set to "display: flex," and that tells all of it's immediate children to line the fuck UP! Done, columns made. This is the new way to create columns. Flexbox gives you all kinds of settings to control the position, order, alignment, size and behavior of it's contents. Flexbox fucking rocks and should be used all the time. I use Table-Cell as a fall back in browsers that don't support flexbox. I do this because table-cell has the closest behavior to Flexbox and it gives me vertical and horizontal centering.
.container
.col-6-12
.content
p Bushwick fanny pack high life wolf single-origin coffee american apparel, cred twee gluten-free mixtape mlkshk ethical carles Austin direct trade. Etsy banksy biodiesel ethnic, cardigan chambray lomo four loko single-origin coffee. Wes anderson dreamcatcher chillwave whatever, before they sold out master cleanse polaroid fixie skateboard yr.
.col-6-12
.content
p Mcsweeney's PBR typewriter banksy wes anderson helvetica. Synth sriracha salvia, selvage pour-over 3 wolf moon 8-bit cosby sweater street art swag. Artisan echo park shoreditch, semiotics iphone dreamcatcher farm-to-table pinterest flexitarian cred ennui irony bicycle rights. Narwhal whatever etsy retro, kogi yr salvia fixie pork belly master cleanse wolf ethical PBR VHS.
.container
.col-4-12
.content
p Bushwick fanny pack high life wolf single-origin coffee american apparel, cred twee gluten-free mixtape mlkshk ethical carles Austin direct trade.
.col-4-12
.content
p Bushwick fanny pack high life wolf single-origin coffee american apparel.
.col-4-12
.content
p Bushwick fanny pack high life wolf single-origin coffee american apparel, cred twee gluten-free mixtape mlkshk ethical carles Austin direct trade.
.perimeter__colophone
h2 Outtro
p.description All grids are responsive, yet none use any breakpoints. I wanted to show the vanilla behavior of each technique when resized.
*
box-sizing border-box
:root
font-size 18px
body
background-color #eee
color #333
font-family source sans pro
font-weight 200
line-height 1.25
margin-top 2rem
h1
font-size 8vw
font-weight 900
padding 1rem
text-align center
text-shadow 5px 5px 0 #ccc
text-transform uppercase
h2
font-size 5vw
font-weight 600
position relative
text-align center
text-shadow 5px 5px 0 #eee
text-transform uppercase
&::after
border-bottom 5px solid #333
bottom -1rem
content: ''
left 50%
position absolute
transform translateX(-50%)
width 6rem
a
background-color #0fc
color #333
text-decoration none
&:hover
background-color #333
color #0fc
.description
font-family source serif pro
line-height 1.5
padding 2rem 6rem
[class^=perimeter]
background-color white
box-shadow 10px 10px 0 #ddd
margin 4rem auto
padding 2rem
width 80vmax
.content
background-color #333
color #ddd
margin 1rem
padding 1rem
[class^=col]
background:
repeating-linear-gradient(
-45deg,
transparent,
transparent 25%,
#0fc 0,
#0fc 50%
),
#333
background-size: 2rem 2rem
//height 6rem
[class*='6-12']
width (6/12) * 100%
[class*='4-12']
width (4/12) * 100%
.perimeter
&__float
margin-top 2rem
.container
overflow hidden
.col-6-12,
.col-4-12
float left
&__inline-block
.container
text-align center
.col-6-12,
.col-4-12
display inline-block
margin-right -3px
//vertical-align top
&__table-cell
.container
display table
.col-6-12,
.col-4-12
display table-cell
&__flex
.container
display flex
Also see: Tab Triggers