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 URL's 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 it's URL and the proper URL extention.
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.
-var lines = [
- ["it's", 'quarter', 'half'],
- ['ten', 'twenty', 'five'],
- ['to', 'past', 'one', 'two'],
- ['three', 'four', 'five'],
- ['six', 'seven', 'eight'],
- ['nine', 'ten', 'eleven'],
- ['twelve', "o'clock"]
-]
.clock
.rivets.top
.content
each line in lines
.line
each word in line
span.word= word
.dots
each index in [1, 2, 3, 4]
span.dot= index
.rivets.bottom
#ticker.ticker
// reset
@import '//codepen.io/chrisdothtml/pen/ojLzJK.css'
// settings
clock-size = 500px
clock-gutter = 65px
rivet-size = 17px
rivet-margin = 10px
dot-size = 15px
dot-margin = 15px
// general reference
line-count = 7
dot-count = 4
$rivet
background-color: #efefef
width: rivet-size
height: rivet-size
position: absolute
border-radius: 50%
box-shadow: -3px -3px 5px 0 rgba(0, 0, 0, .4) inset
$item
opacity: .2
transition: all 0.3s
&.active
opacity: 1
$word
@extends $item
font-family: 'Titillium Web', sans-serif
font-size: 43px
color: #fff
text-transform: uppercase
&.active
text-shadow: 0px 0px 10px rgba(255, 255, 255, .4)
$dot
@extends $item
background-color: #fff
width: dot-size
height: dot-size
html
width: 100%
min-width: clock-size + 50px
height: 100%
min-height: clock-size + 70px
position: relative
body
background: url(https://s3-us-west-2.amazonaws.com/s.cdpn.io/216995/wood_pattern.png)
.clock
background-color: #212121
width: clock-size
height: clock-size
margin: 20px auto 0
position: relative
z-index: 2
border-radius: 8px
box-shadow: 5px 5px 15px 2px rgba(0, 0, 0, .4)
.content
width: 100%
height: 100%
padding: clock-gutter
position: absolute
.line
display: flex
justify-content: space-between
.word
@extends $word
display: block
line-height: ((clock-size - (clock-gutter * 2)) / line-count)
.dots
display: flex
justify-content: space-between
width: (dot-size * dot-count) + (dot-margin * (dot-count - 1))
position: absolute
bottom: (clock-gutter / 2)
left: 50%
transform: translate(-50%, 50%)
.dot
@extends $dot
display: block
// hide text
text-indent: 100%
white-space: nowrap
overflow: hidden
.rivets
&:before,
&:after
@extends $rivet
content: ''
&:before
left: rivet-margin
&:after
right: rivet-margin
&.top
&:before,
&:after
top: rivet-margin
&.bottom
&:before,
&:after
bottom: rivet-margin
.ticker
width: 100%
line-height: 1
font-size: 25px
color: #c59e62
text-align: center
position: absolute
bottom: 5px
z-index: 1
text-shadow: -1px -1px 1px #2b2418
const $items = getItems()
const permItems = ['its']
/**
* @returns {object}
*/
function getItems () {
const result = {}
const dots = '.clock .content .dots .dot'
const words = '.clock .content .line .word'
$(words).each(function () {
const $word = $(this)
let label = $word.text().replace('\'', '')
if (result[label]) {
label += '2'
}
result[label] = $word
})
$(dots).each(function () {
const $dot = $(this)
const label = $dot.text()
result['dot' + label] = $dot
})
result.all = $(`${dots}, ${words}`)
return result
}
/**
* Updates time ticker
*/
function updateTicker () {
const time = moment().format('hh:mm:ss')
$('#ticker').text(time)
}
/**
* Resets and activates new items
*/
function updateClock (items) {
$items.all.removeClass('active')
items.forEach(item => {
$items[item].addClass('active')
})
}
/**
* Determines the proper hour item(s) to use
*
* @returns {array}
*/
function getHourItems (hour, minutes) {
const result = []
const map = { 1: 'one', 2: 'two', 3: 'three', 4: 'four',
5: 'five2', 6: 'six', 7: 'seven', 8: 'eight', 9: 'nine',
10: 'ten2', 11: 'eleven', 12: 'twelve' }
// direction only applies to minutes > 4
if (minutes > 4) {
let direction
if (minutes > 34) {
direction = 'to'
// use next hour
if (hour === 12) {
hour = 1
} else {
hour++
}
} else {
direction = 'past'
}
result.push(direction)
}
result.push(map[hour])
return result
}
/**
* Determines the proper minute item(s) to use
*
* @returns {array}
*/
function getMinuteItems (minutes) {
const map = {
'0-4': ['oclock'],
'5-9,55-59': ['five'],
'10-14,50-54': ['ten'],
'15-19,45-49': ['quarter'],
'20-24,40-44': ['twenty'],
'25-29,35-39': ['twenty', 'five'],
'30-34': ['half']
}
let result = []
// each map range
mapLoop:
for (let ranges in map) {
let items = map[ranges]
let rangesArr = ranges.split(',')
// each 'n-n' segment
for (let i = 0; i < rangesArr.length; i++) {
let range = rangesArr[i].split('-')
let floor = range[0]
let ceil = range[1]
// minutes match map range
if (minutes >= floor && minutes <= ceil) {
result = result.concat(items)
// dots for overflow minutes
if (minutes > floor) {
let remainder = minutes - floor
for (let i = 1; i <= remainder; i++) {
result.push('dot' + i)
}
}
break mapLoop
}
}
}
return result
}
/**
* Determines what items need to be activated for the
* current time
*
* @returns {array}
*/
function getTimeItems () {
const time = moment()
const hour = Number(time.format('h'))
const minutes = time.minutes()
return []
.concat(getHourItems(hour, minutes))
.concat(getMinuteItems(minutes))
.concat(permItems)
}
/**
* Updates clock with current time
*/
function update () {
const newItems = getTimeItems()
updateClock(newItems)
updateTicker()
}
// start ticking
new Tock({
interval: 1000,
callback: update
}).start()
Also see: Tab Triggers