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.
<!doctype html>
<!-- forked from https://codepen.io/carl-vega/pen/KbGyYX -->
<html lang="en">
<head>
<title>Vertical demo</title>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel = "stylesheet" type = "text/css" href = "./styles.css" />
</head>
<style>
</style>
<body>
<div class="container">
<div class="box box-1">box 1</div>
<div class="box box-2">box 2
Example for SO: <a href="https://stackoverflow.com/questions/25098042/fill-remaining-vertical-space-with-css-using-displayflex">Fill remaining vertical space with CSS using display:flex</a>
<hr/>
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Maecenas eleifend fermentum varius. Nunc laoreet suscipit nisl, aliquet pellentesque mauris pharetra vel. Proin feugiat blandit nulla nec rutrum. Fusce ac est dignissim, eleifend metus eget, pulvinar erat. Praesent tempus dui consequat vehicula sagittis. Aenean eros lectus, venenatis tristique commodo non, finibus sed mi. Nam non lobortis nisl. Proin sapien nibh, lobortis ac tempus vel, scelerisque eu orci. Suspendisse cursus, libero eu tincidunt consectetur, diam velit consequat nisl, quis sollicitudin ante lacus non odio. Pellentesque erat sapien, volutpat ac diam vel, semper fermentum ipsum. In consequat urna id sollicitudin euismod. Curabitur nec viverra leo.
Phasellus eget consectetur augue. Sed tempor, turpis sodales convallis molestie, tellus tortor porttitor ligula, vitae vehicula mauris dui et diam. Curabitur egestas imperdiet efficitur. Aenean massa justo, commodo nec tellus nec, suscipit venenatis velit. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nullam auctor dui nec faucibus fermentum. Nullam faucibus felis sit amet nisi lobortis, in auctor turpis malesuada. Quisque sed pharetra diam. Phasellus a euismod nulla, nec pellentesque risus. Pellentesque at consequat dui. Orci varius natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus. Praesent diam lacus, varius a tempor at, imperdiet vel tortor. Fusce mollis aliquam velit ut mollis. Nunc quis justo at odio auctor convallis.
Curabitur interdum lacinia suscipit. Proin vulputate magna sed dolor semper, id suscipit nisi scelerisque. Suspendisse eu turpis vel ex rutrum ullamcorper. Nulla sed lacus consequat, malesuada nulla vitae, tristique erat. Vestibulum ornare odio ut tempus rhoncus. Nullam at elementum neque, quis dictum turpis. Proin auctor vulputate tortor. Etiam dictum elementum pretium. Ut ornare felis eget nisl facilisis, ac lacinia arcu convallis. Praesent laoreet ullamcorper lobortis. Curabitur volutpat dolor nisi, non mollis velit vulputate sit amet. Mauris faucibus enim in varius mattis.
Duis arcu ipsum, congue vitae orci ut, sollicitudin hendrerit metus. Suspendisse imperdiet dolor metus, ut hendrerit arcu rhoncus sit amet. Aenean vitae facilisis lacus. Mauris ut volutpat eros. Quisque ullamcorper vel mauris at egestas. Nullam risus ex, pretium vel lectus ullamcorper, venenatis iaculis ante. Sed eget semper arcu. Fusce porttitor egestas enim eget sodales. Mauris leo orci, tempor sed nisl at, tristique convallis dolor. Suspendisse sed nibh id mauris aliquet accumsan. Nulla porttitor fringilla gravida. Interdum et malesuada fames ac ante ipsum primis in faucibus. Mauris at diam mauris.
Duis non gravida mi, et efficitur purus. Maecenas commodo ultrices nisl, quis finibus nunc bibendum quis. In ornare fermentum justo, id suscipit dui varius vel. Proin at pharetra nisi. Morbi diam lectus, bibendum id tempor non, euismod non leo. Praesent in placerat mi. Duis nunc leo, viverra placerat ante ac, lobortis dignissim diam. Nullam euismod justo et fermentum pharetra. Integer aliquet vehicula tortor vel sodales.
</div>
<div class="box box-3">box 3</div>
</div>
</body>
</html>
*{
/*
https://developer.mozilla.org/en-US/docs/Web/CSS/box-sizing
It is often useful to set box-sizing to border-box to layout elements. This makes dealing with the sizes of elements much easier, and generally eliminates a number of pitfalls you can stumble on while laying out your content.
On the other hand, when using position: relative or position: absolute, use of box-sizing: content-box allows the positioning values to be relative to the content, and independent of changes to border and padding sizes, which is sometimes desirable.*/
box-sizing: border-box;
margin: 0px;
padding: 0px;
}
/* ALL CONTAINER up to the flex container, including the flex container itself */
html,
body,
.container {
/* necessary */
height: 100%;
min-height: 100%;
}
.container {
/* for the flex container */
display: flex;
flex-direction: column;
}
.container .box {
text-align: center;
font-family: sans-serif;
font-size: 30px;
// padding: 20px;
/* not necessary
this is actually for the each box content to be aligned inside of it */
// display: flex;
// flex-direction: column;
// justify-content: center;
}
.container .box-1 {
background-color: red;
// height is used for this cell as preferred
// https://www.w3.org/TR/css-sizing-3/#preferred-size-properties
// but not obeyed! when size of the page becomes too small to accomodate it
// in that case it does contributes but not obeyed, as for example min-height
// https://www.w3.org/TR/css-sizing-3/#min-size-properties
// height: 400px;
// if you uncoment flex, it will take precedence
// preferred over its (in this case) euqivalente https://www.w3.org/TR/css-flexbox-1/#propdef-flex-grow
// flex: 1;
}
.container .box-2 {
background-color: blue;
// height is not taken into consideration as a preffered size
// when flex directive is provided
// https://www.w3.org/TR/css-flexbox-1/#propdef-flex says:
/** When a box is a flex item, flex is consulted **instead of the [main size property](https://www.w3.org/TR/css-flexbox-1/#main-size-property)** to determine the main size of the box */
// height: 400px;
flex: 1;
overflow-y: auto;
}
.container .box-3 {
background-color: white;
// flex: 2;
// it is overwritten by flex directive and not respected any more
/* **WARNING**: if this value is set to smaller than necessary for the inner content to fit, we will endup with the overflow and vertical page scroller, which can surely avoided with `overflow-y: scroll;`*/
height: 60px;
// height: 30px;
// overflow-y: scroll;
// however, `min-height` is still taken in the consideration in the same manner, so if flex directive can be accomodated without breaking min-height, it will be, but if it cannot the min-height will be respected, even for the price of introducing the scroller on the whole page
// min-height: 220px;
// similar to `max-height`; it is still taken in the consideration
// max-height: 100px;
}
Also see: Tab Triggers