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="app">
<div class="title">
<h1>Clip-Path: Simple Shapes</h1>
</div>
<div class="panel">
<label for="shapes">Shapes</label>
<select id="shapes" v-model="currentTransition">
<option value="circle">circle</option>
<option value="ellipse">ellipse</option>
<option value="inset">inset</option>
<option value="polygon">polygon</option>
</select>
<label for="modes">Modes</label>
<select id="modes" v-model="mode">
<option value="">none</option>
<option value="out-in">out-in</option>
<option value="in-out">in-out</option>
</select>
<button @click="transition">transition</button>
</div>
<div class="boxes">
<transition :name="currentTransition" :mode="mode">
<box1 v-if="box1"></box1>
<box2 v-else></box2>
</transition>
</div>
<div class="example">
<transition name="fade" mode="out-in">
<div class="container" :key="currentTransition" v-html="descriptions[currentTransition]"></div>
</transition>
</div>
<div class="instructions">
<ul>
<li>Choose from four different types of clip-path shapes in the "Shapes" dropdown.</li>
<li>Choose from the different Vue Transition Component modes in the "Modes" dropdown that control the order of the boxes transitioning.</li>
<li>Click the "Transition" button to see the selected options being animated.</li>
</ul>
</div>
</div>
@import url('https://fonts.googleapis.com/css?family=Luckiest+Guy');
html {
box-sizing: border-box;
font-family: -apple-system,BlinkMacSystemFont,"Segoe UI",Roboto,Oxygen-Sans,Ubuntu,Cantarell,"Helvetica Neue",sans-serif;
}
*, *:before, *:after {
box-sizing: inherit;
}
html,
body {
background-color: #1d1e22;
margin: 0;
padding: 0;
}
body {
align-items: center;
display: flex;
height: 100vh;
justify-content: center;
}
#app {
display: grid;
grid-template-columns: 150px 300px 350px;
grid-gap: 20px;
.title {
color: #FFF;
grid-column: 1 / 4;
h1 {
font-size: 20px;
font-weight: bold;
}
}
.instructions {
color: #FFF;
grid-column: 1 / 4;
ul {
list-style: disc;
}
li {
margin-bottom: 10px;
}
}
}
.panel {
display: flex;
flex-direction: column;
label {
color: #fff;
}
button,
select {
font-size: 18px;
margin: 10px 0;
padding: 5px 0;
}
}
.boxes {
align-items: center;
background-color: #C5C5C5;
border: 3px solid #FFF;
display: flex;
height: 300px;
justify-content: center;
width: 300px;
&::before {
background-color: darken(#C5C5C5, 10%);
content: '';
display: block;
height: 200px;
position: absolute;
width: 200px;
}
&::after {
align-items: center;
background-color: rgba(0, 0, 0, 0.8);
color: #fff;
content: "Sorry!\A\AThis browser doesn't support this type of clip-path animations!";
display: flex;
height: 200px;
position: absolute;
text-align: center;
white-space: pre-wrap;
width: 200px;
}
.box {
align-items: center;
background-color: #307B21;
color: #fff;
display: flex;
font-family: 'Luckiest Guy';
font-size: 60px;
height: 200px;
justify-content: center;
position: absolute;
width: 200px;
}
.box2 {
background-color: #4371AD;
}
}
@supports(clip-path: circle(0)) {
.boxes::after {
display: none;
}
}
.example {
color: #FFF;
p {
margin-bottom: 10px;
}
.container {
width: 350px;
}
}
.fade-enter,
.fade-leave-to { opacity: 0; }
.fade-enter-active,
.fade-leave-active { transition: 500ms; position: absolute; }
.circle-enter-active { animation: 1s circle reverse; }
.circle-leave-active { animation: 1s circle; }
@keyframes circle {
0% { clip-path: circle(75%); }
100% { clip-path: circle(0%); }
}
.ellipse-enter-active { animation: 1s ellipse reverse; }
.ellipse-leave-active { animation: 1s ellipse; }
@keyframes ellipse {
0% { clip-path: ellipse(80% 80%); }
100% { clip-path: ellipse(0% 20%); }
}
.inset-enter-active { animation: 1s inset reverse; }
.inset-leave-active { animation: 1s inset; }
@keyframes inset {
0% { clip-path: inset(0% round 0%); }
100% { clip-path: inset(50% round 50%); }
}
.polygon-enter-active { animation: 1s polygon reverse; }
.polygon-leave-active { animation: 1s polygon; }
@keyframes polygon {
0% { clip-path: polygon(0 0, 50% 0, 100% 0, 100% 50%, 100% 100%, 50% 100%, 0 100%, 0 50%); }
100% { clip-path: polygon(50% 50%, 50% 25%, 50% 50%, 75% 50%, 50% 50%, 50% 75%, 50% 50%, 25% 50%); }
}
Vue.component('box1', {
template: '<div class="box box1">box1</div>'
});
Vue.component('box2', {
template: '<div class="box box2">box2</div>'
});
new Vue({
el: "#app",
data: {
box1: true,
currentTransition: 'circle',
mode: 'out-in',
descriptions: {
circle: '<p>The circle shape is set with a radius.</p><p>In this example the circle is animated from 75% (to go beyond the box elements) down to 0% (to essentially disappear) in the leave transition.</p><p>The animation is reversed in the enter transition.</p>',
ellipse: '<p>The ellipse shape is set with two radii, one for x and y directions of the shape.</p><p>In this example the ellipse is animated from (80% 80%) to (0% 20%) in the leave transition. This shrinks the ellipse down to nothing in a non-circular fashion.</p><p>The animation is reversed in the enter transition.</p>',
inset: '<p>The inset shape can be defined as a distance inward from one, two, or four sides of the parent.</p><p>In this example the inset is animated from 0% to 50% in the leave transition, essentially disappearing. At the same time the corners are rounded (same as border-radius) from 0% to 50%. This gives it the appearance of changing from a square to a circle as it animates.</p><p>The animation is reversed in the enter transition.</p>',
polygon: '<p>The polygon shape is defined by at least three vertices with x and y coordinates each within the parent. Straight lines will connect each vertex in order to create the final shape. Two vertices at the same coordinates will appear to be "welded" together. To be animated smoothly, there must always be a consistent number of vertices.</p><p>In this example eight vertices are created; the four corners animate inward to the center and the points on the four sides animate inward to halfway to the center. This essentially makes the shape disappear in the enter transition.</p><p>The animation is reversed in the enter transition.</p>'
}
},
methods: {
transition () {
this.box1 = !this.box1;
}
}
})
Also see: Tab Triggers