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.
<div id="clock"></div>
/**
* Variables
*/
$color__light_blue: #CAE4F2;
$color__dark_blue: #2A6FB0; /* 42, 111, 176 */
$color__dark_blue_alpha: rgba(42,111,176,0.3);
$color__dark_blue_dark_alpha: rgba(42,111,176,0.8);
$color__light_green: #65C0A5;
$color__dark_green: #0B8972; /* #35a66f
*/
$color__dark_green_alpha: #6DB8AA;
$color__light_red: #F17259;
$color__light_red_alpha: #F38E7A;
$color__dark_red: #9D1313;
$font_stack__body: 'Nunito', 'Quicksand', 'Valero Round', sans-serif;
$font_stack__headings: 'Sonsie One', cursive;
$section_height: 100vh;
$section_width: calc( 100vw + 17px );
$post_width: 600px;
* {
position: relative;
margin: 0;
padding: 0;
box-sizing: border-box;
}
body {
font-size: 16px;
background: $color__light_blue;
font-family: $font_stack__body;
font-weight: 100;
letter-spacing: -0.2px;
line-height: 1.6;
overflow: hidden;
}
h1, h2, h3, h4, h5, h6 {
font-family: $font_stack__headings;
}
/**
* Countdown Clock
*/
.countdown-clock {
width: 560px;
height: 120px;
position: absolute;
top: 120px;
left: 50%;
transform: translateX(-50%);
text-align: center;
color: $color__dark_blue;
opacity: 0.3;
border-top: 2px solid $color__dark_blue;
border-bottom: 2px solid $color__dark_blue;
}
.pie {
fill: transparent;
stroke: white;
stroke-width: 100;
stroke-dasharray: 0 100;
transition: stroke-dasharray .3s ease;
}
.pie-plate {
position: absolute;
top: -8px;
left: -20px;
z-index: -1;
background: transparent;
border-radius: 50%;
display: block;
transform: rotate(-90deg);
}
#countdown {
list-style: none;
margin-bottom: 1em;
}
#countdown li {
display: inline-block;
margin: 1em 2em;
position: relative;
max-width: 60px;
text-align: center;
}
#countdown .number {
font-size: 3em;
margin: 10px 0 0;
padding: 0;
line-height: 1;
}
#countdown .label {
margin-top: -5px;
}
/*
* Let it snow!
*/
$.fn.snow();
/**
* Countdown Component
*/
var Countdown = React.createClass({
render: function() {
return (
<div className="countdown-clock">
<ul id="countdown">
<li id="days">
<div className="number">00</div>
<div className="label">Days</div>
<svg width="100" height="100" className="pie-plate">
<circle r="50" cx="50" cy="50" className="pie" />
</svg>
</li>
<li id="hours">
<div className="number">00</div>
<div className="label">Hours</div>
<svg width="100" height="100" className="pie-plate">
<circle r="50" cx="50" cy="50" className="pie" />
</svg>
</li>
<li id="minutes">
<div className="number">00</div>
<div className="label">Minutes</div>
<svg width="100" height="100" className="pie-plate">
<circle r="50" cx="50" cy="50" className="pie" stroke-dasharray="10"/>
</svg>
</li>
<li id="seconds">
<div className="number">00</div>
<div className="label">Seconds</div>
<svg width="100" height="100" className="pie-plate">
<circle r="50" cx="50" cy="50" className="pie" />
</svg>
</li>
</ul>
<p>Remaining 'til Christmas <span className="this-year"></span></p>
</div>
)
}
});
ReactDOM.render(
<Countdown/>,
document.querySelector('#clock')
);
/**
* Date Countdown timer
* @link https://codepen.io/chrisjdesigner/pen/dMbmoE
*/
var thisYear = new Date();
var thisChristmas = thisYear.getFullYear() + "/12/25 00:00:00";
var christmas = new Date( thisChristmas ),
days, hours, mins, secs;
/* Display the current Year in the subheading */
$('.this-year').text( thisYear.getFullYear() );
$(function() {
// Calculate time to Christmas
timeToXmas();
// Transition from 0
numberTrans( '#days .number', days, 1000, 'easeOutQuad' );
numberTrans( '#hours .number', hours, 1000, 'easeOutQuad' );
numberTrans( '#minutes .number', mins, 1000, 'easeOutQuad' );
numberTrans( '#seconds .number', secs, 1000, 'easeOutQuad' );
// Begin countdown
setTimeout( countdownTimer, 1001 );
});
// function to calc Time to Christmas
function timeToXmas() {
var today = new Date();
// diff between dates
var diff = (today - christmas)/1000;
var diff = Math.abs(Math.floor(diff));
// Day to target
days = Math.floor(diff/(24*60*60));
secs = diff - days * 24*60*60;
// Hours
hours = Math.floor(secs/(60*60));
secs = secs - hours * 60*60;
// Minutes
mins = Math.floor(secs/60);
secs = secs - mins * 60;
}
// function to display the countdown Timer
function countdownTimer() {
timeToXmas();
// display in front-end clock
// Seems like multiplying by 360(degrees) gives an inaccurate measure - 315 is the proper number to be an even division of the pie graph clock
$( '#days .number' ).text(days);
var dayResult = 315*(days/25) + ' ' + 360;
$( '#days .pie' ).css( { "stroke-dasharray": dayResult } );
$( '#hours .number' ).text(hours);
var hrResult = 315*(hours/24) + ' ' + 360;
$( '#hours .pie' ).css( { "stroke-dasharray": hrResult } );
$( '#minutes .number' ).text(mins);
var minResult = 315*(mins/60) + ' ' + 360;
$( '#minutes .pie' ).css( { "stroke-dasharray": minResult } );
$( '#seconds .number' ).text(secs);
var secResult = 315*(secs/60) + ' ' + 360;
$( '#seconds .pie' ).css( { "stroke-dasharray": secResult } );
// repeat every second
setTimeout(countdownTimer, 1000);
}
// Transition numbers
function numberTrans( id, endpt, transDur, transEase ) {
$({numberCount: $(id).text()}).animate({numberCount: endpt}, {
duration: transDur,
easing: transEase,
step: function() {
$(id).text(Math.floor(this.numberCount));
},
complete: function() {
$(id).text(this.numberCount);
}
});
};
Also see: Tab Triggers