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.
<!-- do we really need to bother with IE9 now? -->
<!--[if lte IE 9]>
<style>
ul.text-slide a:after{display:none}
ul.text-slide a:hover{
top:-25px;
background:#eee;color:#444;
}
ul.text-slide a:hover b{color:#444}
</style>
<![endif]-->
<body id="bodytop">
<div id="toggle" class="hamburger"> <a class="menu-open" href="#toggle"> <span class="toggle"><i>Menu open</i></span> </a> <a class="menu-close" href="#bodytop" id="toggle2"> <span class="toggle"><i>Menu Close</i></span> </a> </div>
<div class="wrap">
<header class="header">
<h1>My Logo/Name</h1>
<nav class="main-nav">
<ul class="text-slide">
<!-- the nested 'b' element is just used for the text-slide effect and not needed for the centering demo -->
<li><a href="#"><b>Link 1</b></a></li>
<li><a href="#"><b>Link 2</b></a></li>
<li><a href="#"><b>Link 3</b></a></li>
<li><a href="#"><b>Link 4</b></a></li>
<li><a href="#"><b>Link 5</b></a></li>
<li><a href="#"><b>Link 6</b></a></li>
<li><a href="#"><b>Link 7</b></a></li>
</ul>
</nav>
<p class="sign-reg"><a class="sign-in" href="#">Sign In</a> <a class="register" href="#">Register</a></p>
</header>
<main class="main">
<h2>Main content here</h2>
<p>The main nav links above will remain centred in the viewport even though the logo and sign-in links are uneven lengths. The main caveat is that the nav links will not be allowed to wrap as white-space:nowrap is used to force them onto one line.
Therefore you will need to use a media query to change the behaviour at about 860px or whatever your layout requires.</p>
</main>
<footer class="footer">
<h3>Footer content here</h3>
</footer>
</div>
</body>
html {
box-sizing: border-box;
}
*,
*:before,
*:after {
box-sizing: inherit;
}
html,
body {
margin: 0;
padding: 0;
height: 100%;
}
body {
font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica,
Arial, sans-serif;
}
.wrap {
background: #f9f9f9;
max-width: 1170px;
margin: auto;
display: flex;
flex-direction: column;
min-height: 100%;
}
.header {
display: flex;
padding: 10px;
background: #eee;
align-items: center;
border-bottom: 2px solid #000;
}
.header h1 {
margin: 0;
padding: 0 10px 0 0;
}
.main-nav {
flex: 1 0 0%;
white-space: nowrap;
transition: 0.5s ease;
}
.header h1,
.sign-reg {
flex-basis: 50%;
}
.main-nav ul {
margin: 0;
padding: 0;
list-style: none;
display: flex;
}
.main-nav a {
display: block;
padding: 10px;
color: #fff;
background: #000;
text-decoration: none;
border: 1px solid #fff;
}
/* code below just for a sliding effect on the nav links and is not needed for main demo */
ul.text-slide {
height: 2rem;
font-family: Arial, Helvetica, sans-serif;
font-size: 0.8rem;
margin: 0;
padding: 0;
list-style: none;
}
ul.text-slide li {
border: 1px solid #444444;
border-right: 1px solid #fff;
height: 2rem;
overflow: hidden;
}
ul.text-slide li:last-child {
border-right: 1px solid #444;
}
ul.text-slide a {
padding: 0;
border: none;
position: relative;
top: -2rem;
padding-top: 2rem;
text-decoration: none;
background: #444;
-moz-transition: top 0.2s linear;
-webkit-transition: top 0.2s linear;
transition: top 0.2s linear;
}
ul.text-slide a:after {
content: " ";
background: #eee;
position: absolute;
top: 0px;
left: 0;
right: 0;
height: 2rem;
z-index: 2;
}
ul.text-slide a:hover {
top: 0;
}
ul.text-slide a b {
outline: none;
padding: 0 15px;
display: block;
position: relative;
z-index: 3;
font-weight: normal;
text-shadow: 0 -2rem 0px #444;
color: #fff;
height: 2rem;
line-height: 2rem;
}
/* end text effect code */
p.sign-reg {
margin: 0;
padding: 0 0 0 10px;
display: flex;
justify-content: flex-end;
}
.sign-reg a {
padding: 10px;
white-space: nowrap;
}
.main {
background: #ccc;
padding: 10px;
flex: 1 0 0%; /* remove this if you don't want main's background to reach footer*/
}
.footer {
background: #000;
padding: 10px;
color: #fff;
margin-top: auto;
}
.hamburger {
display: none;
}
/* media queries for smaller display */
@media screen and (max-width: 860px) {
.wrap {
margin: 0;
}
.header {
padding-left: 40px;
}
.header h1 {
padding-left: 10px;
}
.main-nav {
position: fixed;
left: 0;
top: 0;
bottom: 0;
width: 100%;
z-index: 999;
background: rgba(255, 255, 255, 0.9);
overflow: auto;
flex-wrap: wrap;
transform: translateX(-100%);
}
.main-nav ul {
height: auto;
flex-wrap: wrap;
}
.main-nav li {
flex: 1 0 100%;
}
/* hamburger styles */
.hamburger {
position: fixed;
display: block;
left: 10px;
top: 15px;
z-index: 1000;
transition: 0.5s ease;
width: 35px;
height: 35px;
background:blueviolet;
transition-delay: 0.5s;
}
.hamburger a {
background: transparent;
color: transparent;
position: absolute;
top: 0;
left: 1px;
width: 32px;
height: 35px;
overflow: hidden;
}
/* hamburger menu */
.toggle {
position: absolute;
top: 7px;
left: 3px;
background: transparent;
padding: 0;
margin: 0;
cursor: pointer;
outline: none;
width: 26px;
height: 21px;
border: none;
border-top: 3px solid #fff;
border-bottom: 3px solid #fff;
text-decoration: none;
color: #ccc;
outline: 0;
}
.toggle i {
opacity: 0;
}
.toggle:before,
.toggle:after {
content: "";
display: block;
width: 26px;
height: 3px;
top: 6px;
left: 0;
background: #fff;
position: absolute;
}
.toggle,
.toggle:before,
.toggle:after {
transition: all 0.3s ease;
transform: rotate(0deg);
}
.hamburger:target .toggle {
border-color: transparent;
}
.hamburger:target .toggle:before {
transform: rotate(45deg);
}
.hamburger:target .toggle:after {
transform: rotate(-45deg);
}
.menu-close {
z-index: -1;
}
.hamburger:target .menu-open {
opacity: 0;
}
.hamburger:target .menu-close {
z-index: 2;
}
/* nav styles open */
.main-nav {
padding-top: 45px;
}
.main-nav li,
.main-nav li a {
background: transparent;
border: none;
}
ul.text-slide {
height: auto;
font-size: 1.5rem;
}
ul.text-slide li {
border: none;
}
.hamburger:target + .wrap .main-nav {
transform: translateX(0);
background: rgba(255, 255, 255, 1);
transition-delay: 1s;
}
.hamburger:target {
left: 92%;
transition-delay: 0.5s;
}
.hamburger:target + .wrap .main-nav a,
.hamburger:target + .wrap ul.text-slide li {
border-bottom: 1px solid #000;
}
ul.text-slide {
height: auto;
}
ul.text-slide li {
border: none;
border-bottom: 1px solid #000;
height: 3rem;
}
ul.text-slide li:last-child {
border-right: none;
}
ul.text-slide a {
top: -3rem;
padding-top: 3rem;
font-size: 1.5rem;
color:#000;
}
ul.text-slide a:after {
height: 3rem;
}
ul.text-slide a b {
text-shadow: 0 -3rem 0px #444;
height: 3rem;
line-height: 3rem;
color:#000;
}
/* end text effect code */
}
@media screen and (max-width: 480px) {
h1 {
font-size: 1rem;
}
}
//nope
Also see: Tab Triggers