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.
<div class="container">
<div class="brand x-brand">
<h1>Our X brands</h1>
<ul>
<li><a href="#">Brand X01</a>
<li><a href="#">Brand X02</a>
<li><a href="#">Brand X03</a>
<li><a href="#">Brand X04</a>
<li><a href="#">Brand X05</a>
<li><a href="#">Brand X06</a>
<li><a href="#">Brand X07</a>
<li><a href="#">Brand X08</a>
<li><a href="#">Brand X09</a>
<li><a href="#">Brand X10</a>
<li><a href="#">Brand X12</a>
<li><a href="#">Brand X13</a>
</ul>
</div>
<div class="brand y-brand">
<h1>Our Y brands</h1>
<ul>
<li><a href="#">Brand Y01</a>
<li><a href="#">Brand Y02</a>
<li><a href="#">Brand Y03</a>
<li><a href="#">Brand Y04</a>
<li><a href="#">Brand Y05</a>
<li><a href="#">Brand Y06</a>
<li><a href="#">Brand Y07</a>
<li><a href="#">Brand Y08</a>
</ul>
</div>
<div class="brand z-brand">
<h1>Our Z brands</h1>
<ul>
<li><a href="#">Brand Z01</a>
<li><a href="#">Brand Z02</a>
<li><a href="#">Brand Z03</a>
<li><a href="#">Brand Z04</a>
<li><a href="#">Brand Z05</a>
<li><a href="#">Brand Z06</a>
<li><a href="#">Brand Z07</a>
<li><a href="#">Brand Z08</a>
<li><a href="#">Brand Z09</a>
<li><a href="#">Brand Z10</a>
</ul>
</div>
</div>
@import compass
html
height: 100%
body
min-height: 100%
color: #fff
background: #7a7480
@include background-image(linear-gradient(top, #474150, #7a7480))
background-repeat: no-repeat
font-family: avenir, sans-serif
font-size: 14px
ul,li
margin: 0
padding: 0
list-style: none
.container
position: relative
max-width: 940px
margin: 30px auto
padding: 10px
@include(single-box-shadow(0,1px,5px,rgba(0,0,0,0.5)))
border: 1px solid #7a7480
border-width: 0 1px 0 1px
overflow: hidden
.brand
position: relative
height: 100px
h1
display: block
float: left
margin: 0 10px 0 0
padding: 10px 10px 20px 0
opacity: 0.3
font-size: 14px
font-weight: bold
cursor: pointer
-webkit-transition: opacity 300ms
-moz-transition: opacity 300ms
transition: opacity 300ms
&:hover
opacity: 1
ul
position: absolute
left: 0
top: 30px
height: 60px
z-index: 1
overflow: hidden
white-space: nowrap
li
display: inline-block
a
display: block
margin: 5px 10px 0 0
padding: 15px
color: #fff
text-decoration: none
background: rgba(255,0,0,0.2)
.y-brand
a
background: rgba(0,255,0,0.2)
.z-brand
a
background: rgba(0,0,255,0.2)
.enhanced1
height: 100px
.brand
height: auto
ul
top: 140px
&.on,
&.hover
h1
opacity: 1
ul
top: 40px
z-index: 2
&.on
h1
color: #fc0
/* loading */
.csstransitions .enhanced2
ul
top: 40px
li
max-width: 150px
-webkit-transition: -webkit-transform 300ms,opacity 300ms
-moz-transition: -moz-transform 300ms,opacity 300ms
transition: transform 300ms,opacity 300ms
&.fade1
opacity: 0 !important
-webkit-transition: -webkit-transform 500ms,opacity 500ms
-moz-transition: -moz-transform 500ms,opacity 500ms
transition: transform 500ms,opacity 500ms
-webkit-transform: translate3d(0,60px,0) !important
-moz-transform: translate3d(0,60px,0) !important
transform: translate3d(0,60px,0) !important
&.fade2
-webkit-transition: max-width 500ms ease-out
-moz-transition: max-width 500ms ease-out
transition: max-width 500ms ease-out
max-width: 0 !important
overflow: hidden
li,
&.hover .brand.on li
opacity: 0
-webkit-transform: translate3d(0,100px,0)
-moz-transform: translate3d(0,100px,0)
transform: translate3d(0,100px,0)
.on li,
.hover li,
&.hover .on.hover li
opacity: 1
-webkit-transform: translate3d(0,0,0)
-moz-transform: translate3d(0,0,0)
transform: translate3d(0,0,0)
li:nth-child(2)
-webkit-transition-delay: 20ms
-moz-transition-delay: 20ms
transition-delay: 20ms
li:nth-child(3)
-webkit-transition-delay: 40ms
-moz-transition-delay: 40ms
transition-delay: 40ms
li:nth-child(4)
-webkit-transition-delay: 60ms
-moz-transition-delay: 60ms
transition-delay: 60ms
li:nth-child(5)
-webkit-transition-delay: 80ms
-moz-transition-delay: 80ms
transition-delay: 80ms
li:nth-child(6)
-webkit-transition-delay: 100ms
-moz-transition-delay: 100ms
transition-delay: 100ms
li:nth-child(7)
-webkit-transition-delay: 120ms
-moz-transition-delay: 120ms
transition-delay: 120ms
li:nth-child(8)
-webkit-transition-delay: 140ms
-moz-transition-delay: 140ms
transition-delay: 140ms
li:nth-child(9)
-webkit-transition-delay: 160ms
-moz-transition-delay: 160ms
transition-delay: 160ms
li:nth-child(10)
-webkit-transition-delay: 180ms
-moz-transition-delay: 180ms
transition-delay: 180ms
li:nth-child(11)
-webkit-transition-delay: 200ms
-moz-transition-delay: 200ms
transition-delay: 200ms
li:nth-child(12)
-webkit-transition-delay: 220ms
-moz-transition-delay: 220ms
transition-delay: 220ms
li:nth-child(13)
-webkit-transition-delay: 240ms
-moz-transition-delay: 240ms
transition-delay: 240ms
a
-webkit-transition: -webkit-transform 300ms
-moz-transition: -webkit-transform 300ms
transition: -webkit-transform 300ms
&:hover
-webkit-transform: scale(1.2)
-moz-transform: scale(1.2)
transform: scale(1.2)
// .enhanced1 = javascript enabled, show/hide logo bars
// .enhanced2 = css transitions enabled, animations
var brandBar = (function() {
var goNow = true;
var IntervalObj = {};
var waitDuration = 5000;
var fade1Duration = 500;
var fade2Duration = 1000;
var cssTransitions = false;
var goRounds = $('.brand ul');
// init
var init = function() {
// initial dom set-up
$('.container').addClass('enhanced1');
if (Modernizr.csstransitions) {
$('.container').addClass('enhanced2');
cssTransitions = true;
}
$('.brand').first().addClass('on');
// set-up menu switching events
brandSwitch();
// set-up the logo carousels
brandGoRoundInit();
// recalc carousel necessity on resize
$(window).resize(function() {
brandGoRoundInit();
})
}
// events to switch brand menus
var brandSwitch = function() {
$('.brand')
.hover(
function(ev){
goNow = false;
if ($('.container').hasClass('enhanced2')) {
$('.container').addClass('hover')
$(this).addClass('hover')
}
},function(ev) {
goNow = true;
$('.container').removeClass('hover')
$(this).removeClass('hover')
}
)
.click(function(ev){
$('.brand').removeClass('on');
$(this).addClass('on')
})
}
// set up each brand menu by seeing if they need to carousel
var brandGoRoundInit = function() {
var maxWidth = $('.container').width();
goRounds.each(function(i,el){
var thisWidth = $(el).width();
if (thisWidth > maxWidth - 12) {
IntervalObj[i] = setInterval(function() {
brandGoRoundLoop(i);
},waitDuration);
} else {
clearTimeout(IntervalObj[i]);
}
})
}
// single carousel loop
var brandGoRoundLoop = function(i) {
var thisUl = goRounds.slice(i,i+1);
// if mouseover menu, skip loop
if (!goNow)
return
// if this menu is not on, skip loop
if (!thisUl.closest('.brand').hasClass('on'))
return;
var firstBrand = thisUl.find('li').first();
if (cssTransitions) {
firstBrand.addClass('fade1');
setTimeout(function() {
firstBrand.addClass('fade2');
setTimeout(function() {
lastBrand = firstBrand.clone().removeClass('fade1 fade2');
firstBrand.remove();
thisUl.append(lastBrand);
},fade2Duration);
},fade1Duration);
};
}
// closure
return {
init: init
}
})()
// go!
brandBar.init();
Also see: Tab Triggers