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.
h1 Slideshow
h2 using cool 3d showcase effects
section.slideshow
ul.items
li.item
h3 First
div.img.first
h4 1
span Put your website layout / whatever here
li.item
h3 Second
div.img.second
h4 2
span Put your website layout / whatever here
li.item
h3 Third
div.img.third
h4 3
span Put your website layout / whatever here
li.item
h3 Fourth
div.img.fourth
h4 4
span Put your website layout / whatever here
div.nav
button.prev
button.next
body
background: hsl(0, 100, 60)
font-family: sans-serif
h1, h2
position: absolute
left: 50%
transform: translateX(-50%)
font-family: sans-serif
text-transform: uppercase
letter-spacing: 2px
h1
top: 24px
color: hsl(0, 0, 100)
font-size: 12px
h2
top: 44px
color: hsl(0, 0, 100)
font-size: 10px
opacity: 0.7
.slideshow
position: absolute
width: 650px
height: 350px
top: 150px
left: 50%
background: hsl(0, 0, 100)
border-radius: 4px
box-shadow: 0 3px 18px hsl(0, 100, 40)
transform: translateX(-50%)
.item
position: absolute
width: 100%
height: 100%
opacity: 0
transition: all 0.4s ease-in-out
perspective: 800px
h3
position: absolute
bottom: -6px
left: 15px
color: hsl(0, 0, 85)
font-size: 50px
font-weight: bold
text-transform: uppercase
letter-spacing: 2px
.img
position: absolute
width: 320px
height: 500px
bottom: -30px
right: 100px
border-radius: 3px
opacity: 0
transition: transform 0.4s ease-in-out
transform: rotateX(45deg) rotateZ(-30deg) translateY(0%)
h4
position: absolute
bottom: -16px
right: 0
opacity: 0.4
color: hsl(0, 0, 100)
font-size: 160px
span
position: absolute
top: 50%
left: 50%
color: hsl(0, 0, 100)
font-size: 14px
text-align: center
text-shadow: -1px 1px 1px hsl(0, 0, 30)
line-height: 20px
transform: translate(-50%, -50%)
.item.on
z-index: 1
opacity: 1
transition: all 0.4s ease-in-out
.img
opacity: 1
animation: on 0.6s ease-in-out
animation-fill-mode: forwards
.img.first
background: hsl(210, 80, 30)
box-shadow: -3px 3px hsl(210, 80, 20)
.img.second
background: hsl(30, 80, 70)
box-shadow: -3px 3px hsl(30, 80, 60)
.img.third
background: hsl(270, 60, 50)
box-shadow: -3px 3px hsl(270, 60, 40)
.img.fourth
background: hsl(170, 40, 30)
box-shadow: -3px 3px hsl(170, 40, 20)
.nav
z-index: 10
position: absolute
bottom: -15px
right: 20px
border-radius: 20px
box-shadow: 0 8px 18px hsl(0, 100, 40)
button
position: relative
display: block
float: left
width: 50px
height: 40px
background: hsl(0, 100, 60)
box-shadow: 0 0 0 3px hsl(0, 0, 100) inset
border: none
outline: none
cursor: pointer
&::before, &::after
position: absolute
content: ''
&::before
width: 16px
height: 2px
top: 19px
background: hsl(0, 0, 100)
&::after
width: 6px
height: 6px
top: 16px
border-top: 2px solid hsl(0, 0, 100)
button.next
margin-left: -3px
border-top-right-radius: 20px
border-bottom-right-radius: 20px
cursor: e-resize
&::before
left: 15px
&::after
left: 24px
border-right: 2px solid hsl(0, 0, 100)
transform: rotate(45deg)
button.prev
border-top-left-radius: 20px
border-bottom-left-radius: 20px
cursor: w-resize
&::before
right: 15px
&::after
right: 24px
border-left: 2px solid hsl(0, 0, 100)
transform: rotate(-45deg)
@keyframes on
from
opacity: 0
transform: rotateX(45deg) rotateZ(-30deg) translateY(20%)
to
transform: rotateX(45deg) rotateZ(-30deg) translateY(0%)
// Still one error in console when we click next on last element or previous on first element. It is trying to add 'on' class on an empty element right before we go back to first/last child. Im working on it but help is always appreciated :3
function init() {
first.classList.add('first', 'on');
last.classList.add('last');
}
function slide(target) {
var current = document.querySelector('.items .on'),
next = current.nextElementSibling,
prev = current.previousElementSibling;
current.classList.remove('on');
if (target.classList.contains('next') && current.classList.contains('last')) first.classList.add('on');
if (target.classList.contains('next')) next.classList.add('on');
if (target.classList.contains('prev') && current.classList.contains('first')) last.classList.add('on');
if (target.classList.contains('prev')) prev.classList.add('on');
}
var first = document.querySelector('.items li:first-child'),
last = document.querySelector('.items li:last-child');
window.onload = init;
document.body.onmouseup = function (event) {
var target = event.target || event.toElement;
if (target.tagName.toLowerCase() == 'button') slide(target);
};
Also see: Tab Triggers