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.
<div id="root" class="root">
<div class="container">
<div class="header">
<div class="menu">
<span class="hamb">
<span class="row"></span>
<span class="row"></span>
<span class="row"></span>
</span>
</div>
<svg class="curve-background">
<path class="curve-open"
fill="#313131"
d="M740,60 L740,0 680,0 C690,50, 690,50 740,60"/>
<path class="curve-close"
fill="#FFD34E"
d="M0,405 L0,405 740,405 740,405 C370,440 370,440 740,405"/>
</svg>
<div class="search">
<svg class="search-icon" enable-background="new 0 0 50 50" height="34px"
viewBox="0 0 50 50" width="34px">
<rect fill="none" height="50" width="50"/>
<circle cx="21" cy="20" fill="none" r="15" stroke="#fff" stroke-width="5"/>
<line class="search-line" fill="none" stroke="#fff" stroke-width="5" x1="32.229" x2="49.9" y1="32.229" y2="49.9"/>
</svg>
<span class="close">✖</span>
</div>
</div>
<div class="text">
<h1 class="search-text">search</h1>
<input type="text" class="search-input"/>
</div>
<div class="intro">
<h1>Click Search Button</h1>
</div>
<div class="footer">
<ul class="list">
<li class="list-item"></li>
<li class="list-item"></li>
<li class="list-item"></li>
<li class="list-item"></li>
<li class="list-item"></li>
<li class="list-item"></li>
<li class="list-item"></li>
</ul>
</div>
</div>
</div>
$containerWidth = 740px
$containerHeight = 435px
$buttonWidth = 60px
$footerHeight = 30px
@import url(https://fonts.googleapis.com/css?family=Roboto:500,500italic,400,400italic,300,300italic);
@keyframes search-open {
50% {
transform translate3d(-350px, 187px,0) rotate(180deg)
}
100% {
transform translate3d(-225px, 187px,0) rotate(360deg)
}
}
@keyframes search-close {
0%{
transform translate3d(-225px, 187px,0) rotate(0deg)
}
100%{
transform translate3d(0px,0px,0) rotate(360deg)
}
}
*
box-sizing border-box
html
body
height 100%
body
margin 0
padding 0
background #FFD34E
font-family 'Roboto', serif
#root
display flex
height inherit
.container
width $containerWidth
height $containerHeight
background #FFD34E
margin auto
box-shadow 0 0 20px 5px rgba(0,0,0,.2)
display flex
flex-direction column
justify-content space-between
position relative
.curve-background
overflow hidden
position absolute
width $containerWidth
left 0
height $containerHeight - $footerHeight
/.search-open & .curve-close
opacity 0
/.search-close & .curve-close
opacity 1
.header
display flex
justify-content space-between
.menu
.search
width $buttonWidth
height $buttonWidth
background #313131
transition background .5s ease-out 0s
z-index 50
position relative
cursor pointer
/.search-open &
background #FFD34E
/.search-close &
background #313131
.close
opacity 0
font-size 2.5rem
color white
position absolute
left 15px
top 0
/.search-open &
opacity 1
/.search-close &
opacity 0
.menu
border-bottom-right-radius 50%
text-align center
line-height 70px
.hamb
display inline-block
width 30px
height 18px
line-height 0
.row
display inherit
background #fff
height 4px
margin-bottom 3px
width 100%
.search
border-bottom-left-radius 50%
text-align center
padding 13px 0
circle
.search-line
stroke white
transition stroke .4s ease-out
/.search-open & .search-icon
animation search-open 1s forwards
circle
.search-line
stroke #313131
/.search-close & .search-icon
animation search-close .5s forwards
circle
.search-line
stroke white
.text
text-align center
color white
z-index 10
font-size 1.3rem
margin-top -90px
transition opacity .5s ease-in
.search-input
height 40px
border none
border-radius 3px
width 0
transition all .5s ease-out .4s
padding 0
/.search-open &
width 270px
/.search-close &
transition all 0s
width 0
.search-text
transform translate(0, 40px)
margin 0
transition all .5s ease-out .4s
opacity 0
margin-bottom 10px
/.search-open &
opacity 1
transform translate(0,0)
/.search-close &
transition all 0s
transform translate(0, 40px)
opacity 0
.intro
color white
text-align center
position absolute
top 165px
width 100%
transition opacity .3s ease-in
/.search-open &
opacity 0
/.search-close &
opacity 1
.footer
background white
height $footerHeight
text-align center
line-height @height
.list
margin 0
padding 0
display inline-block
list-style none
.list-item
display inline-block
width 7px
height 7px
border-radius 7px
margin-right 15px
background silver
window.requestAnimFrame = (function() {
return window.requestAnimationFrame ||
window.webkitRequestAnimationFrame ||
window.mozRequestAnimationFrame ||
window.oRequestAnimationFrame ||
window.msRequestAnimationFrame ||
function(callback) {
window.setTimeout(callback, 1000 / 60);
};
})();
window.onload = ()=>{
let $search = document.querySelector('.search');
let $root = document.querySelector('.root');
let $curveOpen = document.querySelector('.curve-open');
let $curveClose = document.querySelector('.curve-close');
let stateOpen = {topPointX:680,
bottomPointY:60,
curvePointX:690,
curvePointY:50};
let propsOpen = {topPointX:-150,
bottomPointY:500,
curvePointX:-150,
curvePointY:450};
let stateClose = {
leftPointY:405,
rightPointY:405,
curvePointY:500
};
let propsClose = {
leftPointY:0,
rightPointY:0,
curvePointY:0
};
let drawClose = ({leftPointY,rightPointY,curvePointY}) =>{
$curveClose.setAttribute('d',`M0,${leftPointY} L0,405 740,405 740,${rightPointY} C370,${curvePointY} 370,${curvePointY} 0,${leftPointY}`)
};
let drawOpen = ({topPointX, bottomPointY, curvePointX, curvePointY})=>{
$curveOpen.setAttribute('d',`M740,${bottomPointY} L740,0 ${topPointX},0 C${curvePointX},${curvePointY} ${curvePointX},${curvePointY} 740,${bottomPointY}`)
};
$search.addEventListener('click',()=>{
let classes = $root.classList;
if(classes.contains('search-open') && classes.contains('search-close')){
classes.remove('search-close');
animate(300, drawOpen, stateOpen, propsOpen);
}else if(classes.contains('search-open')){
classes.add('search-close');
animate(300, drawClose, stateClose, propsClose);
}else{
classes.add('search-open');
animate(300, drawOpen, stateOpen, propsOpen);
}
});
let animate = (time, draw, state, props) =>{
let fCount = 1;
let start = performance.now();
let framesCount = time/(1000 / 60);
let keys = Object.keys(props);
let deltaState = {};
let stepState = {};
keys.map((i)=>{
(state[i] < props[i])?
deltaState[i] = (props[i] - state[i])
:deltaState[i] = -(state[i] - props[i])
});
let _animate = (timestamp) =>{
if((timestamp - start) < time){
keys.map((j)=>{
stepState[j] = state[j] + (deltaState[j]*(fCount/framesCount))
});
draw(stepState);
fCount++;
requestAnimFrame(_animate)
}else{
if(fCount <= framesCount){
draw(props);
}
}
};
requestAnimFrame(_animate);
}
};
Also see: Tab Triggers