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.
<section class="section__1">
<h1>Yes, this is that presentation</h1>
<p>It's about flexbox</p>
</section>
<section class="section__1">
<h1>S1: flex-direction: row (default)</h1>
<div class="flex ">
<div class="item">s1 item 1</div>
<div class="item">s1 item 2</div>
<div class="item">s1 Some more txt in this item</div>
<div class="item">s1 item 4</div>
</div>
<p>items will display as a row and line up at the start of that axis. <br>still space at the end of the flex container.</p>
</section>
<section class="section__1-b">
<h1>S1-b: flex-direction: row but with more text</h1>
<div class="flex ">
<div class="item">s1 item 1</div>
<div class="item">s1 item 2</div>
<div class="item">This behavior is likely to be familiar to you if you have ever used Flexbox, but perhaps you have wondered how the browser is working that sizing out, as if you look in multiple modern browsers you will see that they all do the same thing</div>
</div>
<p>more text to these items so they will fill the container</p>
</section>
<section class="section__1-c">
<h1>S1-c:
flex-grow:1 / flex-basis: auto
</h1>
<div class="flex">
<div class="item">Wouldn't</div>
<div class="item">we</div>
<div class="item">better start farming potatoes ?</div>
</div>
<p>short version: flex: 1 1 auto ==> default</p>
</section>
<section class="section__1-c">
<h1>S1-c with more text:
flex-grow:0 / flex-basis: auto
</h1>
<div class="flex">
<div class="item">Wouldn't</div>
<div class="item">we</div>
<div class="item">This behavior is likely to be familiar to you if you have ever used Flexbox, but perhaps you have wondered how the browser </div>
</div>
<p>No space to distribute here</p>
</section>
<section class="section__1-d">
<h1>S1-d: Flex-basis: 0</h1>
<div class="flex ">
<div class="item">Wouldn't</div>
<div class="item">we</div>
<div class="item">This behavior is likely to be familiar to you if you have ever used Flexbox, but perhaps you have wondered how the browser </div>
</div>
<p>short version: flex: 1 1 0; <br>flex-basis to 0 and flex-grow to 1 <br> all of our boxes: no starting width <br>so space in flex container is shared out evenly</p>
</section>
<hr>
<section class="section__2">
<h1>S2 : flex-direction: column;</h1>
<div class="flex flex-col">
<div class="item">s2 item 1</div>
<div class="item">s2 item 2</div>
<div class="item">This behavior is likely to be familiar to you if you have ever used Flexbox, but perhaps you have wondered how the browser is working that sizing out, as if you look in multiple modern browsers you will see that they all do the same thing. </div>
</div>
</section>
<section class="section__3">
<h1>S3: flex-direction: row-reverse</h1>
<div class="flex flex-row-reverse">
<div class="item flex-grow">s3 item 1</div>
<div class="item flex-grow">s3 item 2</div>
<div class="item flex-grow">s3 item 3</div>
</div>
<p>Reverse the order of items in a row direction</p>
</section>
<section class="section__4">
<h1>S4: flex-direction: col-reverse</h1>
<div class="flex flex-col-reverse">
<div class="item flex-grow">s4 item 1</div>
<div class="item flex-grow">s4 item 2</div>
<div class="item flex-grow">s4 item 3</div>
</div>
<p>Reverse the order of items in a column direction</p>
</section>
<hr>
<section class="section__5">
<h1>S5 Flex-wrap but no grow</h1>
<div class="flex flex-wrap">
<div class="item">Orange potato</div>
<div class="item">Sprout tomato pea</div>
<div class="item">Gumbo beet</div>
<div class="item">greens corn soko</div>
<div class="item">endive gumbo gourd.</div>
<div class="item">Parsley shallot courgette tatsoi pea</div>
</div>
<p>Makes the items (flex-grow: 0) wrap to the next row</p>
</section>
<section class="section__5">
<h1>S5 Flex-wrap with growing items</h1>
<div class="flex flex-wrap">
<div class="item flex-grow">Orange potato</div>
<div class="item flex-grow">Sprout tomato pea</div>
<div class="item flex-grow">Gumbo beet</div>
<div class="item flex-grow">greens corn soko</div>
<div class="item flex-grow">endive gumbo gourd.</div>
<div class="item flex-grow">Parsley shallot courgette tatsoi pea</div>
</div>
<p>Makes the items (flex-grow: 1) wrap to the next row</p>
</section>
<hr>
<section class="section__6">
<h1>S6 Ordering items</h1>
<div class="flex">
<div class="item">first item</div>
<div class="item">second item</div>
<div class="item">third item</div>
<div class="item">fourth item</div>
<div class="item">last item</div>
</div>
<p>Order in the flexbox container !!</p>
</section>
<hr>
<section class="section__7">
<h1>S7 Justification: center</h1>
<div class="flex">
<div class="item">first item - some more content</div>
<div class="item">second item</div>
<div class="item">third item</div>
<div class="item">fourth item</div>
<div class="item">last item</div>
</div>
<p>Justify: center</p>
</section>
<section class="section__7b">
<h1>S7b Justification: space-between</h1>
<div class="flex justify-between">
<div class="item">first item - some more content</div>
<div class="item">second item</div>
<div class="item">third item</div>
<div class="item">fourth item</div>
<div class="item">last item</div>
</div>
<p>Justify: spread the available space "between" the items</p>
</section>
<section class="section__7c">
<h1>S7c Justification: space-around</h1>
<div class="flex justify-around">
<div class="item">first item - some more content</div>
<div class="item">second item</div>
<div class="item">third item</div>
<div class="item">fourth item</div>
<div class="item">last item</div>
</div>
<p>Justify: spread the available space "around" the items</p>
</section>
<section class="section__8">
<h1>S8 Practical example</h1>
<div class="nav-wrapper border border-dashed border-blue-400 flex flex-col-reverse md:flex-col">
<nav class="meta flex flex-col sm:flex-row justify-between items-center">
<div class="search p-2 flex">
Search
<input class="searchBox-query form-control ml-4 px-4 border border-solid border-grey-500" name="query" placeholder="Zoeken" type="search">
</div>
<div class="languages">
<ul class="flex flex-row">
<li><a class="p-2" href="">Nederlands</a></li>
<li><a class="p-2" href="">Frans</a></li>
<li><a class="p-2" href="">Engels</a></li>
</ul>
</div>
</nav>
<header class="header flex flex-col sm:flex-row justify-between items-center bg-white p-2 sm:p4"><a href="/" class="flex items-center text-gray-800 active--exact active"><span class="font-bold hidden sm:inline-block sm:visible">Site Home</span></a><nav class="nav flex flex-col sm:flex-row"><a href="/works" class="nav__link uppercase text-black text-sm font-medium p-2 hover:text-red-600">Works</a><a href="/about" class="nav__link uppercase text-black text-sm font-medium p-2 hover:text-red-600">About</a><a href="/blog" class="nav__link uppercase text-black text-sm font-medium p-2 hover:text-red-600">Blog</a><a href="/wp" class="nav__link uppercase text-black text-sm font-medium p-2 hover:text-red-600">WP</a><a href="/kitchen-sink" class="nav__link uppercase text-black text-sm font-medium p-2 hover:text-red-600">Sink</a><a href="/contact" class="nav__link uppercase text-black text-sm font-medium p-2 hover:text-red-600">Contact</a></nav></header>
</div>
<p>Meta nav is on top, except on mobile where the meta nav is on the bottom. <br>Via flex-column-reverse on the parent container.</p>
</section>
<section class="section__9">
<h1>S9 Center center</h1>
<div class="flex justify-center items-center" style="height: 300px">
<div class="item">first item - some more content</div>
</div>
<p>justify-content: center + align-items: center</p>
</section>
<section class="section__9b">
<h1>S9b Center center (align-items)</h1>
<div class="flex justify-center items-center" style="height: 300px">
<div class="item">first item - some more content</div>
<div class="item">second item</div>
</div>
<p>justify-content: center + align-items: center <br>aligns the items inside a flex container along the cross axis just like justify-content does along the main axis.</p>
</section>
:root {
--main-bg-color: rgba(255,0,0,.15);
--div-bg-color: rgba(0,0,0,1);
}
section {
height: 100vh;
border: 1px solid #ddd;
display: flex;
flex-direction: column;
justify-content: space-around;
> div {
border: 2px solid var(--div-bg-color);
// padding: 1rem;
}
}
.item {
background: var(--main-bg-color);
border: 2px solid ;
padding: .5rem
}
.section__1-c {
.item {
flex-grow: 1;
flex-shrink: 1;
flex-basis: auto;
}
}
.section__1-d {
.item {
flex-grow: 1;
flex-shrink: 1;
flex-basis: 0;
}
}
.section__6 {
.item:nth-of-type(1) { order: 3; }
.item:nth-of-type(2) { order: 4; }
.item:nth-of-type(3) { order: 1; }
.item:nth-of-type(4) { order: 5; }
.item:nth-of-type(5) { order: 2; }
.item:last-child {
order: -1;
}
}
.section__7 {
> div {
justify-content: center;
.item {
// flex-grow: 1;
}
}
}
// codepen
body {
width: 70vw;
margin: 0 auto;
display: flex;
flex-direction: column;
// flex-direction: column-reverse;
}
h1, p {
text-align: center;
color: #777;
margin: 1em 0;
}
h1 {
font-size: 1.6em;
color: black;
}
// https://www.smashingmagazine.com/2018/09/flexbox-sizing-flexible-box/
// https://yoksel.github.io/flex-cheatsheet/
Also see: Tab Triggers