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.
<link href="https://fonts.googleapis.com/css?family=Quicksand:300,400,500,700" rel="stylesheet">
<div class="warning">
This page uses <a href="https://css-tricks.com/snippets/css/complete-guide-grid/" title="CSS Grid Layout" target="_blank">CSS Grid Layout</a>. If you are reading this message, your browser does not support this feature and you may not be able to see a grid of example boxes. You can check the browser compatibility <a href="http://caniuse.com/#feat=css-grid" title="Can I Use CSS Grid Layout" target="_blank">here</a>.
</div>
<h1>Simple Animations using CSS Borders</h1>
<h3>Hover your mouse on the examples below to see the effect.</h3>
<div class="grid-container">
<div>
<h2>1. Interchange border colors</h2>
<div class="box box1"></div>
</div>
<div>
<h2>2. Expand width</h2>
<div class="box box2"></div>
</div>
<div>
<h2>3. Expand width & height</h2>
<div class="box box3"></div>
</div>
<div>
<h2>4. Rotate border colors using keyframe animations</h2>
<div class="box box4"></div>
</div>
<div>
<h2>5. Four colored circle</h2>
<div class="box box5"></div>
</div>
<div>
<h2>6. Two colored triangle</h2>
<div class="box box6"></div>
</div>
<div>
<h2>7. Two colored square</h2>
<div class="box box7"></div>
</div>
<div>
<h2>8. Missing top border</h2>
<div class="box box8"></div>
</div>
<div>
<h2>9. Down Arrow</h2>
<div class="box box9"></div>
</div>
<div>
<h2>10. Left Arrow</h2>
<div class="box box10"></div>
</div>
<div>
<h2>11. Up Arrow</h2>
<div class="box box11"></div>
</div>
<div>
<h2>12. Right Arrow</h2>
<div class="box box12"></div>
</div>
</div>
<footer>
<a href="https://github.com/mpsinghk/animations-using-css-borders" title="Fork on GitHub" target="_blank">Fork on GitHub</a>
</footer>
/* Base
------------------------------------------------------- */
body {
font-family: 'Quicksand', sans-serif;
font-size: calc(16px + 0.3vw);
font-weight: 300;
line-height: 1.4;
text-align: center;
padding: 40px 30px 30px;
}
/* Typography
------------------------------------------------------- */
h1 {
font-size: 3.2em;
line-height: 1.1;
font-weight: 700;
margin: 0 0 0.3em;
}
h2 {
font-size: 1.2em;
line-height: 1.3;
font-weight: 400;
margin: 0 0 0.8em;
}
a,
a:hover,
a:focus {
text-decoration: none;
color: #00a7e3;
}
/* Footer
------------------------------------------------------- */
footer {
font-size: 0.9em;
padding: 20px;
margin-top: 50px;
border-top: 1px solid #ccc;
}
/* CSS Grid Layout
------------------------------------------------------- */
.grid-container {
display: grid;
grid-template-columns: repeat(auto-fit, minmax(310px, 1fr));
grid-gap: 20px;
}
.grid-container > div {
border: 1px solid #ccc;
padding: 30px;
-webkit-box-sizing: border-box;
box-sizing: border-box;
}
/* Warning message if using old browser
that does not support CSS Grid Layout.
------------------------------------------------------- */
.warning {
padding: 20px;
margin-bottom: 30px;
background: #f7b563;
border: 1px solid #e88d1a;
border-radius: 3px;
}
.warning a {
color: #fff;
}
@supports (display: grid) {
.warning {
display: none;
}
}
/* Example boxes
------------------------------------------------------- */
.box {
display: inline-block;
cursor: pointer;
width: 100px;
height: 100px;
border-width: 35px;
border-style: solid;
border-color: cyan magenta yellow black;
-webkit-transition: all 0.3s ease-in-out;
transition: all 0.3s ease-in-out;
}
.box1:hover,
.box1:focus {
border-color: yellow black cyan magenta;
}
.box2 {
width: 0;
}
.box2:hover,
.box2:focus {
width: 100px;
}
.box3 {
width: 0;
height: 0;
}
.box3:hover,
.box3:focus {
width: 100px;
height: 100px;
}
@-webkit-keyframes rotate-borders {
25% { border-color: black cyan magenta yellow; }
50% { border-color: yellow black cyan magenta; }
75% { border-color: magenta yellow black cyan; }
100% { border-color: cyan magenta yellow black; }
}
@keyframes rotate-borders {
25% { border-color: black cyan magenta yellow; }
50% { border-color: yellow black cyan magenta; }
75% { border-color: magenta yellow black cyan; }
100% { border-color: cyan magenta yellow black; }
}
.box4 {
-webkit-animation: rotate-borders 6s infinite;
animation: rotate-borders 6s infinite;
}
.box5:hover,
.box5:focus {
border-radius: 50%;
}
.box6:hover,
.box6:focus {
width: 0;
height: 0;
border-width: 85px;
border-color: transparent magenta yellow transparent;
}
.box7:hover,
.box7:focus {
width: 0;
height: 0;
border-width: 0 170px 170px 0;
border-color: transparent magenta yellow transparent;
}
.box8:hover,
.box8:focus {
width: 0;
height: 0;
border-width: 85px;
border-color: transparent magenta yellow black;
}
.box9:hover,
.box9:focus {
width: 0;
height: 0;
border-width: 170px 85px 0 85px;
border-color: cyan transparent transparent transparent;
}
.box10:hover,
.box10:focus {
width: 0;
height: 0;
border-width: 85px 170px 85px 0;
border-color: transparent magenta transparent transparent;
}
.box11:hover,
.box11:focus {
width: 0;
height: 0;
border-width: 0 85px 170px 85px;
border-color: transparent transparent yellow transparent;
}
.box12:hover,
.box12:focus {
width: 0;
height: 0;
border-width: 85px 0 85px 170px;
border-color: transparent transparent transparent black;
}
// Find me on Instagram
// https://www.instagram.com/mpsinghk
Also see: Tab Triggers