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.
.creature-cage
.creature-body
.eyeball
.brow
#leftPupil
.eyeball.right
.brow.right
#rightPupil
.hair-tuft
.hair
.hair.hair-middle-dark
.hair.hair-right
.hair-tuft.hair-tuft-right
.hair
.hair.hair-middle-dark
.hair.hair-right
.mouth
.tongue
.drool
.hand.hand-left
.finger
.finger.finger-middle
.finger.finger-right
.hand.hand-right
.finger
.finger.finger-middle
.finger.finger-right
body
background-color: dimgray
.eyeball,
.hair-tuft,
#leftPupil,
#rightPupil,
.drool,
.hand
position: absolute
.creature-cage
position: relative
margin: auto
border: .5rem solid #090909
background-color: #eee
@media (min-width: 768px)
width: 24rem
margin-top: 5rem
.creature-body
height: 15rem
margin: 10rem auto 0
border-radius: 60% 60% 0 0
background-color: #5e35b1
.eyeball
width: 50px
height: 50px
top: 30%
left: 20%
border-radius: 50%
padding: 22px
box-shadow: 2px 8px 6px darken(#280680, 5%)
background-color: #1de9b6
&::before
content: ''
position: absolute
width: 20px
height: 15px
border-radius: 50%
background-color: #FFF
z-index: 1
&.right
left: 55%
.brow
position: relative
width: 80px
height: 30px
bottom: 45px
right: 35px
z-index: 20
border: 6px solid
border-radius: 50%
border-color: transparent
box-shadow: 3px -5px 1px #090909
transform: rotate(-20deg)
&.right
transform: rotateY(190deg)
#leftPupil,
#rightPupil
width: 30px
height: 30px
top: 2.3rem
right: 1rem
transform-origin: 1px
border-radius: 50%
padding: 2px
background-color: #090909
&::after
content: ''
position: absolute
width: 32px
height: 32px
bottom: -4px
left: -3px
border: 5px solid #b2ff59
border-radius: 50%
.hair-tuft
width: 65px
height: 50px
left: 10%
bottom: 25%
&.hair-tuft-right
left: 75%
bottom: 13%
transform: rotateY(180deg)
.hair
position: relative
width: 35px
height: 50px
clip-path: polygon(50% 0%, 0 100%, 100% 100%)
background-color: #7441d9
transform: rotateX(180deg)
&.hair-right,
&.hair-right-dark
left: 40%
bottom: 200%
&.hair-middle-dark,
&.hair-middle-light
left: 20%
bottom: 100%
&.hair-middle-dark
background-color: #4f2c94
.mouth
position: relative
width: 19%
height: 21%
left: 39%
top: 45%
border-radius: 13% 13% 50% 50%
background-color: #090909
.tongue
position: relative
width: 72%
height: 26%
left: 7%
bottom: -46%
border: 6.5px dashed
border-color: transparent transparent white
border-radius: 50%
background-color: #ec407a
.drool
top: 61%
width: 10px
border-radius: 27% 50% 20% 77%
box-shadow: 4px 8px 7px darken(#280680, 5%)
background: linear-gradient(#00bcd4, #80deea)
animation: drooling 2.5s 2s cubic-bezier(.73,-0.44,.43,1.49)
animation-fill-mode: forwards
.hand
width: 90px
height: 55px
top: 96%
&.hand-left
left: 10%
transform: rotateY(180deg)
&.hand-right
right: 10%
.finger
position: relative
width: 25%
height: 85%
border-radius: 20% 20% 50% 50%
box-shadow: 0px 3px 15px #090909
background-color: #9162e4
&.finger-middle
width: 25%
height: 94%
left: 29%
bottom: 80%
&.finger-right
width: 20%
height: 68%
left: 60%
bottom: 164%
@keyframes drooling
0%
height: 0px
opacity: 0
70%
height: 20px
100%
height: 42px
opscity: .5
const rightPupil = document.getElementById('rightPupil'),
rightPupilPositionInfo = rightPupil.getBoundingClientRect(),
leftPupil = document.getElementById('leftPupil'),
leftPupilPositionInfo = leftPupil.getBoundingClientRect()
const Eye = class Eye {
constructor(pupilDirection, pupilPositionX, pupilPositionY) {
this.pupilDirection = pupilDirection
this.pupilPositionX = pupilPositionX
this.pupilPositionY = pupilPositionY
}
findAngle(cursorY, cursorX) {
let angleDeg = Math.atan2(cursorY - this.pupilPositionY, cursorX - this.pupilPositionX) * 180 / Math.PI
//angle in degrees
angleDeg = (angleDeg >= 360) ? angleDeg -= 360 : (angleDeg < 0) ? angleDeg += 360 : angleDeg -= 360
this.rotatePupil(angleDeg)
}
rotatePupil(angleDeg) {
this.pupilDirection.style.transform = `rotate(${angleDeg}deg)`
}
}
const rightEye = new Eye(rightPupil, rightPupilPositionInfo.x, rightPupilPositionInfo.y)
const leftEye = new Eye(leftPupil, leftPupilPositionInfo.x, leftPupilPositionInfo.y)
const getCursorCoordinates = (e) => {
let cursorY = (e.clientY),
cursorX = (e.clientX)
rightEye.findAngle(cursorY, cursorX)
leftEye.findAngle(cursorY, cursorX)
}
document.addEventListener('mousemove', getCursorCoordinates, false)
// var eyeFollow = (e) => {
// let y1 = (e.clientY),
// y2 = pupilPositionInfo.y,
// x1 = (e.clientX),
// x2 = pupilPositionInfo.x,
// angleDeg = Math.atan2(y1 - y2, x1 - x2) * 180 / Math.PI; //angle in degrees
// if(angleDeg >= 360){
// angleDeg -= 360;
// }else if(angleDeg < 0){
// angleDeg += 360;
// }
// pupil.style.transform = `rotate(${angleDeg}deg)`
// }
// function eyePoke(e) {
// //gets position of our eye relative to the body
// let x = pupilPositionInfo.x - document.body.offsetLeft,
// y = pupilPositionInfo.y - document.body.offsetTop,
// eyeballWidth = parseInt(window.getComputedStyle(eyeball).getPropertyValue("width")),
// y1 = parseInt((e.clientY) - y),
// x1 = parseInt((e.clientX) - x)
// // checks position cursor to keep it confined to eye area
// if(x1 > 0) x1 -= x1; //15
// if(x1 < (eyeballWidth * -.5)) x1 = -40; //-40
// if(y1 > (eyeballWidth * .25)) y1= 20; //15
// if(y1 < (eyeballWidth * -.5)) y1 = -30; //30
// pupil.style.transform = `translate(${x1}px,${y1}px)`
// }
Also see: Tab Triggers