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.
// Author: Ali Soueidan
// Author URI: https//: www.alisoueidan.com
- var slices = 0;
ul.happy#head
li.slice
.hair
.folds#fold-1
.folds#fold-2
li.slice
.ears#ear-l
.ears#ear-r
.eyes#eye-l
.eyelid
.eyes#eye-r
.eyelid
li.slice
.nose
.hole
.hole
li.slice
.mouth
.teeth.top
.tooth
.tooth
.tooth
.tooth
.tooth
.teeth.bottom
.tooth
.tooth
.tooth
.tooth
.tooth
.corpus
.belly
.chain
ul#nav
li.happy#selected 😃
li.astonished 😲
li.feared 😱
li.anguished 😧
li.angry 😡
li.tired 😪
li.ondrugs 🎁
a( href='http://bit.ly/2JPuBjx' target="_blank" class='reference' ) 🔗 Ali Soueidan
// Author: Ali Soueidan
// Author URI: https//: www.alisoueidan.com
*
list-style: none
margin: 0
padding: 0
$gap: 2vh
$shadow: hsla(0, 0%, 0%, 0.25)
$skin: hsla(169, 100%, 25%, 1)
$skin2: hsla(169, 100%, 20%, 1)
$hair: hsl(0, 100%, 60%)
$mouth: hsla(200, 100%, 25%, 1)
$eyes: hsla(40, 100%, 60%, 1)
$eye-accent-1: hsla(280, 100%, 25%, 1)
$bg: rgba(50,50,100,1)
.reference
position: absolute
right: 24px
bottom: 24px
padding: $gap
color: #fff
font-family: arial
text-decoration: none
background: $bg
box-shadow: 0 0 $gap $shadow
border-radius: $gap
body
display: flex
flex-direction: column
justify-content: center
align-items: center
margin: 0
height: 100vh
background: #fff
ul#nav
position: absolute
transform: translateX(-100%)
top: 0
left: 0
bottom: 0
display: flex
flex-direction: column
justify-content: space-around
align-items: center
padding: $gap*1.5
background: $bg
box-shadow: inset 0 0 $gap/4 $shadow
transition: .8s ease
li
display: flex
justify-content: center
align-items: center
width: $gap*3
max-width: $gap*3
height: $gap*3
max-height: $gap*3
box-shadow: 0 0 $gap/4 $shadow
border-radius: $gap/2
transition: .2s ease
background: #efefef
font-size: $gap*1.5
&#selected
transform: scale(1.2)
background: #fff
&:hover
transform: scale(1.2)
&:hover
cursor: pointer
transform: scale(1.1)
background: #fff
.corpus
position: absolute
z-index: -1
bottom: 0
width: $gap*40
height: 50vh
background: radial-gradient($skin,$skin2)
border-radius: $gap*20 $gap*20 0 0
filter: drop-shadow($gap/2 $gap/2 $gap rgba(0,0,50,.5))
box-shadow: inset $gap $gap $gap rgba(0,0,50,.1)
.chain
position: absolute
top: 0%
left: 50%
transform: translate(-50%, -40%)
width: $gap*15
height: 50vh
border: $gap solid $eyes
border-radius: 50%
filter: drop-shadow(0 0 $gap rgba(0,0,50,.05))
box-shadow: inset $gap $gap $gap rgba(0,0,50,.1)
.belly
position: absolute
bottom: 0
left: 50%
transform: translateX(-50%)
width: $gap*20
height: $gap*10
border-right: $gap solid $shadow
border-left: $gap solid $shadow
border-radius: $gap*10 $gap*10 0 0
filter: drop-shadow($gap $gap $gap rgba(0,0,50,.5))
box-shadow: inset $gap $gap $gap rgba(0,0,50,.1)
#head
position: relative
display: flex
flex-direction: column
justify-content: space-between
margin-bottom: $gap*8
width: $gap*20
height: $gap*30
background: $skin
border-radius: $gap*10
filter: drop-shadow($gap/2 $gap/2 $gap*2 rgba(0,0,50,.5))
box-shadow: inset $gap $gap $gap rgba(0,0,50,.1)
transition: .8s ease
li.slice
width: 100%
height: $gap*5
&:first-child
position: relative
display: flex
flex-direction: column
justify-content: center
align-items: center
border-radius: $gap*10 $gap*10 0 0
height: $gap*10
.hair
position: absolute
top: -$gap
left: 50%
transform: translate(-50%,-50%)
background: $hair
width: $gap*3
height: $gap*4
border-radius: 50%
clip-path: polygon(50% 50%, 70% 0%, 100% 30%, 100% 70%, 70% 100%, 30% 100%, 0% 70%, 0% 30%)
.folds
height: $gap/2
background: $shadow
border-radius: $gap
#fold-1
margin-bottom: $gap
width: 50%
#fold-2
width: 25%
&:nth-child(2)
position: relative
display: flex
justify-content: space-around
align-items: center
.eyebrows
position: absolute
background: red
width: $gap*10
height: $gap*10
transform: rotate(45deg)
.ears
position: absolute
top: 0
height: $gap*5
width: $gap*2
transition: .8s ease
box-shadow: inset 0 0 $gap rgba(0,0,50,.5)
&:before
position: absolute
top: 50%
left: 50%
transform: translate(-50%,-50%)
content: ""
width: $gap/2
height: $gap*3
&#ear-l
left: 0
transform: translateX(-100%)
border-right: $gap/4 solid $shadow
border-radius: $gap*2.5 $gap*2.5 $gap*2.5 $gap*5
background: $skin
&:before
border: $gap/4 solid $shadow
border-right: 1px solid $shadow
border-radius: $gap*2.5 $gap*2.5 $gap*2.5 $gap*5
&#ear-r
right: 0
transform: translateX(100%)
border-left: $gap/4 solid $shadow
border-radius: $gap*2.5 $gap*2.5 $gap*5 $gap*2.5
background: $skin
&:before
border: $gap/4 solid $shadow
border-left: 1px solid $shadow
border-radius: $gap*2.5 $gap*2.5 $gap*5 $gap*2.5
.eyes
position: relative
z-index: 1
display: flex
justify-content: center
align-items: center
height: $gap*5
width: $gap*5
background: $eyes
border: $gap/4 solid $shadow
border-radius: 50%
transition: 1s ease
overflow: hidden
transition: .8s ease
&:before
content: ""
height: $gap*2
width: $gap*2
background: #000
border-radius: 50%
border: $gap/4 solid $eye-accent-1
transition: .8s ease
filter: drop-shadow(0 0 $gap/8 $eye-accent-1)
box-shadow: inset 0 0 $gap/2 rgba(50,50,75,1)
&:after
content: ""
position: absolute
top: 35%
right: 35%
height: $gap/2
width: $gap/2
background: rgba(255,255,255,1)
border-radius: 50%
filter: drop-shadow(0 0 $gap/8 rgba(200,200,200,1))
box-shadow: inset 0 0 $gap/2 rgba(120,120,120,.25)
.eyelid
position: absolute
transform: translateY(-100%)
width: $gap*20
height: $gap*20
background: radial-gradient($skin,$skin2)
transition: .8s ease
&:nth-child(3)
position: relative
display: flex
justify-content: center
align-items: center
.nose
display: flex
justify-content: space-around
align-items: center
height: $gap*5
width: $gap*5
border-top: $gap/2 solid $shadow
border-radius: 50%
transition: .8s ease
filter: drop-shadow(0 $gap/2 $gap/2 rgba(0,0,0,1))
.hole
transform: translateY(-100%)
width: $gap
height: $gap
background: $shadow
border-radius: 50%
&:last-child
display: flex
justify-content: center
align-items: center
border-radius: 0 0 $gap*10 $gap*10
height: $gap*10
.mouth
display: flex
flex-direction: column
justify-content: space-between
align-items: center
width: $gap*12
height: $gap*6
background: $mouth
border-radius: $gap $gap $gap*6 $gap*6
border: $gap/2 solid $shadow
overflow: hidden
transition: .8s ease
filter: drop-shadow(0 0 $gap rgba(0,0,50,.2))
box-shadow: inset 0 0 $gap*4 rgba(0,0,0,.75)
.teeth
display: flex
justify-content: space-around
width: 100%
height: $gap
&.top
.tooth
width: 22%
height: $gap
background: #fff
border-right: $gap/10 solid $shadow
border-bottom: $gap/10 solid $shadow
border-left: $gap/10 solid $shadow
border-radius: $gap/4 $gap/4 $gap/2 $gap/2
filter: drop-shadow(0 0 $gap rgba(0,0,0,.2))
box-shadow: inset 0 0 $gap rgba(200,200,200,.25)
&.bottom
.tooth
width: 22%
height: $gap
border: $gap/10 solid $shadow
background: #fff
border-radius: $gap/2 $gap/2 $gap/4 $gap/4
filter: drop-shadow(0 0 $gap rgba(0,0,0,.2))
box-shadow: inset 0 0 $gap rgba(200,200,200,.25)
&.happy
.eyes
transform: scale(1)
&#eye-l
&:before
transform: scale(1.33)
&#eye-r
&:before
transform: scale(1.33)
&.Astonished
transform: translateY(-$gap*2)
&:first-child
.eyes
transform: scale(.75)
.slice:last-child
.mouth
border-radius: $gap*6 $gap*6 $gap $gap
transform: scale(.75) rotate(-5deg)
&.feared
&:nth-child(1)
.eyes
transform: scale(1.25)
.slice:last-child
.mouth
height: $gap*8
border-radius: $gap*6 $gap*6 $gap*4 $gap*4
&.angry
transform: translateY(-$gap*2) rotate(-5deg)
&:first-child
.ears
width: $gap*1.25!important
.eyes
transform: scale(1)
&#eye-l
clip-path: polygon(30% 0%, 61% 11%, 100% 30%, 100% 70%, 70% 100%, 30% 100%, 0% 70%, 0% 30%)
&:before
transform: scale(.75)
border: $gap solid $eye-accent-1
&#eye-r
clip-path: polygon(34% 14%, 70% 0%, 100% 30%, 100% 70%, 70% 100%, 30% 100%, 0% 70%, 0% 30%)
&:before
transform: scale(.75)
border: $gap solid $eye-accent-1
&:nth-child(1)
.nose
transform: scale(1.2)
.slice:last-child
.mouth
transform: rotate(4deg)
height: $gap*2
border-radius: $gap*6 $gap*6 $gap*4 $gap*4
&.anguished
transform: translateY(-$gap*2) rotate(5deg)
&:nth-child(1)
.eyes
border: $gap/4 solid $skin!important
transform: scale(1)
#eye-l
transform: scale(1.25)
.eyelid
transform: translateY(-62.5%) rotate(-23deg)
&:before
transform: scale(.75)
#eye-r
transform: scale(.75)
.eyelid
transform: translateY(-62.5%) rotate(23deg)
&:before
transform: scale(.75)
.slice:last-child
.mouth
height: $gap*6
border-radius: $gap*2 $gap*2 $gap*6 $gap*6
transform: rotate(-5deg)
&.tired
transform: translateY($gap*4)
&:first-child
.ears
width: $gap*1.75!important
&#ear-l
border-radius: $gap*5 $gap*2.5 $gap*2.5 $gap*2.5!important
&:before
border-radius: $gap*5 $gap*2.5 $gap*2.5 $gap*2.5!important
&#ear-r
border-radius: $gap*2.5 $gap*5 $gap*2.5 $gap*2.5!important
&:before
border-radius: $gap*2.5 $gap*5 $gap*2.5 $gap*2.5!important
.eyes
border: $gap/4 solid $skin!important
transform: scale(.75)
.eyelid
z-index: 1
border-bottom: $gap/2 solid $shadow
border-radius: 50%
#eye-l .eyelid
transform: translateY(-49%)
#eye-r .eyelid
transform: translateY(-52%)
.slice:last-child
.mouth
height: $gap*8
border-radius: $gap*2 $gap*2 $gap*6 $gap*6
transform: rotate(-5deg)
&.ondrugs
transform: translateY(-$gap*2)
&:nth-child(1)
.eyes
transform: scale(1.25)
&#eye-l
&:before
transform: scale(1.75)
border: $gap/6 solid $eye-accent-1
&#eye-r
&:before
transform: scale(1.75)
border: $gap/6 solid $eye-accent-1
&:nth-child(1)
.nose
transform: scale(.75)
.slice:last-child
.mouth
height: $gap*8
border-radius: $gap*2 $gap*2 $gap*6 $gap*6
// Author: Ali Soueidan
// Author URI: https//: www.alisoueidan.com
let target = document.querySelector("#head");
let emotion = document.querySelectorAll("#nav li");
let menu = document.querySelector("#nav");
let i = 0;
emotion.forEach( function() {
emotion[i].addEventListener("click", function() {
clearInterval(walkThrough);
target.removeAttribute("class");
target.classList.add(this.classList[0]);
let i = 0;
emotion.forEach( function() {
emotion[i].removeAttribute("id", "selected");
++i;
});
this.setAttribute("id", "selected");
});
++i;
});
// Walkthrough emotions on start (sparing the last one for better thumbnail)
let n = 1;
let walkThrough = setInterval(() => {
target.removeAttribute("class");
target.classList.add(emotion[n].classList[0]);
++n;
if ( n == emotion.length ) {
target.removeAttribute("class");
target.classList.add(emotion[0].classList[0]);
setTimeout(() => {
menu.style.transform = "translateX(0)";
}, 1000);
clearInterval(walkThrough);
}
}, 1250);
Also see: Tab Triggers