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.
<header>
<h1>Vertical Centering: Everything You Need to Know</h1>
<a href="http://webdesignerwall.com/tutorials/css-vertical-centering-everything-need-know" target="_blank">View Tutorial</a>
</header>
<div class="intro">*Hover over the text to see how each method centers it within its parent.</div>
<div class="container">
<h2>absolute</h2>
<div class="item one"><p>To be able under all circumstances to practice five things constitutes perfect virtue; these five things are gravity, generosity of soul, sincerity, earnestness and kindness.</p></div>
</div>
<div class="container">
<h2>table</h2>
<div class="item two"><p>To be able under all circumstances to practice five things constitutes perfect virtue; these five things are gravity, generosity of soul, sincerity, earnestness and kindness.</p></div>
</div>
<div class="container">
<h2>transform</h2>
<div class="item three"><p>To be able under all circumstances to practice five things constitutes perfect virtue; these five things are gravity, generosity of soul, sincerity, earnestness and kindness.</p></div>
</div>
<div class="container">
<link href="https://maxcdn.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css" rel="stylesheet" integrity="sha384-wvfXpqpZZVQGK6TAh5PVlGOfQNHSoD2xbE+QkPxCAFlNEevoEH3Sl0sibVcOQVnN" crossorigin="anonymous">
<h2>line height</h2>
<div class="item four"><i class="fa fa-css3" aria-hidden="true"></i></div>
</div>
<div class="container">
<h2>padding</h2>
<div class="item five"><p>When I walk along with two others, from at least one I will be able to learn.</p></div>
</div>
<div class="container">
<h2>flexbox</h2>
<div class="item six"><p>To be able under all circumstances to practice six things constitutes perfect virtue; these six things are gravity, generosity of soul, sincerity, earnestness, kindness and vertical alignment.</p><a href="#"> Link </a></div>
</div>
<div class="container">
<h2>Combined Elements</h2>
<div class="item with-image">
<figure><img src="https://24.media.tumblr.com/1d8dd5361a12d9c51077764adf9a1158/tumblr_mvdci7SSY51r4mh0bo1_r1_500.gif"></figure>
<div class="content"><h3>Maybe A Title</h3><p>When I walk along with two others, from at least one I will be able to learn.</p></div>
</div>
</div>
html {
box-sizing: border-box;
}
*,
*:before,
*:after {
box-sizing: inherit;
}
body {
background: linear-gradient(90deg, #f598a8, #f6edb2);
align-items: center;
height: 100vh;
position: relative;
font-family: 'source sans pro', sans-serif;
}
.intro{
font-size: 1.2rem;
display: block;
text-align: center;
color: #555;
font-style: italic;
}
.container {
width: 80vw;
margin: 2vw auto;
border: 0.25rem solid rgba(255, 255, 255, 0.1);
padding: 2vw;
transition: border 0.25s ease;
}
.container h2{
padding: 0 0 0 1rem;
opacity: 0.25;
font-size: 2rem;
transition: opacity 0.25s ease;
}
.item {
position: relative;
background-color: white;
margin: 1rem;
padding: 1rem;
min-height: 33vh;
overflow: hidden;
font-size: 1.25rem;
color: rgba(0, 0, 0, 0.25);
box-shadow: 0 3px 6px rgba(0, 0, 0, 0.16), 0 3px 6px rgba(0, 0, 0, 0.23);
transition: all 0.25s ease;
}
.item:hover {
color: rgba(0, 0, 0, 0.75);
box-shadow: 0 14px 28px rgba(0, 0, 0, 0.25), 0 10px 10px rgba(0, 0, 0, 0.22);
}
.item p{
margin: 0;
padding: 0;
border: 0.25rem dashed rgba(239, 230, 195, 0.1);
}
.item:hover p {
border: 0.25rem dashed rgba(239, 230, 195, 0.75);
}
.item:hover p:after {
opacity: 0.5;
}
/* Positioning */
/* Absolute */
.one p{
position:absolute;
top: 33%;
right:0;
bottom:0;
left:0;
margin: auto;
padding: 0 2rem;
}
/* table */
.two{
display: table;
}
.two p{
display: table-cell;
vertical-align: middle;
}
/* translate */
.three{
height: 33vh;
}
.three p{
position: relative;
top: 50%;
-webkit-transform: translateY(-50%);
-ms-transform: translateY(-50%);
transform: translateY(-50%);
}
/* line height */
.four{
width: 4rem;
height: 4rem;
border-radius: 100%;
margin: 0 auto;
padding: 0;
min-height: auto;
line-height: 4rem;
text-align: center;
}
/* padding */
.five{
padding: 16.5vh 8.25vh;
text-align: center;
}
/* flexbox */
.six{
display: flex;
flex-direction: column;
justify-content: center;
}
/* flexbox with image */
.with-image{
height: auto;
display: flex;
flex-direction: row;
}
.with-image img, .with-image .content{
width: calc(50%);
}
.with-image figure img{
width: 100%;
height: auto;
object-fit: contain;
}
.content{
margin: 0 2rem;
align-self: center;
}
/* General style */
a{
font-size: .8rem;
text-decoration: none;
color: #999;
text-transform: uppercase;
font-family: sans-serif;
}
header{
width: 100%;
display: block;
background: #FFF;
height: 40px;
margin-bottom: 4%;
color: #ccc;
font-family: sans-serif;
font-weight: bold;
box-shadow: 0px 2px 0px 0px rgba(125,121,125,0.3);
overflow: hidden;
}
header h1, header a{
display: inline-block;
font-size: .8rem;
margin: auto 10px;
line-height: 40px;
}
header h1{
text-transform: uppercase;
letter-spacing: 1px;
}
header a{
text-decoration: none;
background-color: #eee;
color: #999;
padding: 0 20px;
transition: all ease-in-out .3s;
}
header a:hover{
background-color: #93dfec;
color: #eee;
margin-left: -3px;
}
@media screen and (max-width: 667px){
.item:not(.four){
min-height: 50vh;
}
.item span{
font-size: 4vw;
}
.with-image{
flex-direction: column;
justify-content: center;
}
.with-image img, .with-image .content{
text-align: center;
width: calc(100%);
height: calc(100%);
}
Also see: Tab Triggers