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 esm.sh, which makes packages from npm not only available on a CDN, but prepares them for native JavaScript ESM 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 id="head">
<nav id="main-navigation" class="navigation">
<a href="#" class="logo">
<div class="logo-text">Lorem Ipsum</div>
</a>
<div class="hamburger-menu">
<div class="hamburger"></div>
</div>
<div class="menu-container">
<ul class="menu">
<li class="menu-link"><a class="link" href="#">Home</a></li>
<li class="menu-link"><a class="link" href="#">About</a></li>
<li class="menu-link"><a class="link" href="#">Office</a></li>
<li class="menu-link">
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Iure reprehenderit, recusandae blanditiis dolores quis quisquam beatae necessitatibus facere, quae a.</p>
</li>
<li class="menu-link menu-line"></li>
<li class="menu-link"><a class="link" href="#">Contact</a></li>
</ul>
<div class="menu-info">
<p>Lorem Ipsum - London • Abbey Road 7 • (060/1234-567)<br/> random@random.com</p>
</div>
</div>
</nav>
</header>
<section>
<article>
<pre>
-- Click on hamburger at top right --
Take bread away from me, if you wish,
take air away, but
do not take from me your laughter.
Do not take away the rose,
the lance flower that you pluck,
the water that suddenly
bursts forth in joy,
the sudden wave
of silver born in you.
My struggle is harsh and I come back
with eyes tired
at times from having seen
the unchanging earth,
but when your laughter enters
it rises to the sky seeking me
and it opens for me all
the doors of life.
My love, in the darkest
hour your laughter
opens, and if suddenly
you see my blood staining
the stones of the street,
laugh, because your laughter
will be for my hands
like a fresh sword.
Next to the sea in the autumn,
your laughter must raise
its foamy cascade,
and in the spring, love,
I want your laughter like
the flower I was waiting for,
the blue flower, the rose
of my echoing country.
Laugh at the night,
at the day, at the moon,
laugh at the twisted
streets of the island,
laugh at this clumsy
boy who loves you,
but when I open
my eyes and close them,
when my steps go,
when my steps return,
deny me bread, air,
light, spring,
but never your laughter
for I would die.
Pablo Neruda
</pre>
</article>
</section>
@import 'https://fonts.googleapis.com/css?family=Calligraffitti';
@import 'https://fonts.googleapis.com/css?family=Montserrat';
$red: #ce3745;
@mixin menu-opened {
$t: .1;
@for $i from 1 through 6 {
$temp: #{.85+$t}s;
.menu-open &:nth-child(#{$i}) {
opacity: 1;
transition: .2s opacity $temp;
}
$t: $t + .1;
}
}
@mixin menu-closed {
@for $i from 1 through 6 {
$temp: #{$i*.05}s;
&:nth-child(#{$i}) {
opacity: 0;
transition: .2s opacity $temp;
}
}
}
html {
font-size: 12px;
}
body {
background: #333;
font-family: 'Montserrat', sans-serif;
padding-top: 50px;
&.menu-open {
overflow: hidden;
}
}
a {
text-decoration: none;
}
*,
*::before,
*::after {
box-sizing: border-box;
margin: 0;
padding: 0;
}
.navigation {
.logo {
position: fixed;
left: 32px;
top: 42px;
z-index: 10;
opacity: 1;
transition: opacity .3s;
.logo-text {
display: inline-block;
font-size: 1.2em;
background-size: cover;
color: #fff;
font-family: 'Calligraffitti', serif;
}
}
.hamburger-menu {
width: 40px;
height: 40px;
position: fixed;
padding: 15px 8px;
top: 32px;
right: 32px;
cursor: pointer;
z-index: 999;
opacity: 1;
&:hover {
.hamburger {
&::before {
transform: translate(0, -1px);
}
&::after {
transform: translate(0, 1px);
}
}
}
.hamburger {
width: 24px;
height: 10px;
position: relative;
&::before,
&::after {
content: '';
width: 24px;
height: 2px;
background: #fff;
position: absolute;
left: 0;
transition: all .3s;
}
&::before {
top: 0;
}
&::after {
top: 8px;
}
}
.menu-open & {
.hamburger {
&::before,
&::after {
background: #fff;
}
&::before {
transform: rotate(45deg);
}
&::after {
top: 0;
transform: rotate(-45deg);
}
}
}
}
.menu-container {
width: 0%;
height: 100%;
position: fixed;
display: block;
top: 0;
right: 0;
z-index: 800;
overflow: hidden;
transition: all .5s cubic-bezier(.99,.04,.87,1) .3s;
background: $red;
opacity: 0;
.menu-open & {
width: 100%;
opacity: 1;
}
.menu {
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
text-align: center;
z-index: 1;
list-style: none;
margin: 0;
@media (max-width: 667px) and (min-width: 320px) and (orientation: landscape) {
display: initial;
li {
display: inline-block;
margin: 0 16px;
&:nth-child(4) {
margin: 0;
}
}
}
li {
@include menu-opened;
@include menu-closed;
padding: 0;
flex: 1;
&:nth-child(4) {
p {
margin: 16px 0;
}
@media (max-width: 667px) and (min-width: 320px) and (orientation: landscape) {
p {
margin: 0;
}
}
}
&.menu-line {
width: 30px;
height: 1px;
background: #fff;
margin: 32px auto 16px;
padding: 0;
flex: initial;
@media (max-width: 667px) and (min-width: 320px) and (orientation: landscape) {
display: none;
}
@media (min-width: 667px) {
width: 1px;
height: 87px;
}
}
a {
display: block;
color: #fff;
font-size: 1.5rem;
transition: color .3s;
padding: 16px 0;
outline: 0;
&:hover {
color: #333;
}
@media (min-width: 1190px) {
font-size: 2rem;
}
}
p {
color: #fff;
font-size: 1rem;
margin-bottom: 0;
@media (min-width: 930px) {
font-size: 1.2rem;
}
@media (min-width: 1190px) {
font-size: 1.5rem;
}
}
}
}
.menu-info {
text-align: center;
position: absolute;
width: 100%;
bottom: 16px;
line-height: 1.6em;
left: 0;
color: #fff;
z-index: 1;
padding: 0 16px;
transform: translate(0, calc(100% + 16px));
transition: .3s 1s;
p {
font-size: 1rem;
margin-bottom: 0;
@media (min-width: 930px) {
font-size: 1.4rem;
}
@media (min-width: 1190px) {
font-size: 1.7rem;
}
}
.menu-open & {
transform: translate(0, 0);
}
}
}
}
section {
margin: 0 90px 0 0;
article {
text-align: center;
margin-top: 50px;
color: #fff;
font-size: 1.5em;
letter-spacing: .12em;
text-shadow: 1px 1px 1px rgba(0, 0, 0, .6);
}
}
//This is just to add/remove menu-open class on body using plain javascript (practice purpose). Jquery code to replace this is:
// $('.hamburger-menu, .link').click(function () {
// $('body').hasClass('menu-open') ? ($('body').removeClass('menu-open')) : ($('body').addClass('menu-open'));
// });
//However, don't forget to include jQuery for it to work.
function toggleMenu() {
var body = document.body;
body.className.match(/(?:^|\s)menu-open(?!\S)/) ? body.className = body.className.replace( /(?:^|\s)menu-open(?!\S)/g , '' ) : body.className += "menu-open";
}
window.onload = function() {
var hamburger = document.getElementsByClassName('hamburger-menu')[0];
var menuLinks = document.getElementsByClassName('link');
hamburger.addEventListener( 'click' , toggleMenu );
for(var i = 0; i < menuLinks.length; ++i) {
var menuLink = menuLinks[i];
menuLink.addEventListener( 'click' , toggleMenu );
}
}
Also see: Tab Triggers