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.
.tl
.timeline.static
each tline in ['checklist', 'liquid', 'hms']
.line(class="#{tline}")
h4 #{tline}
.events
each val in [1, 2, 3, 4, 5]
.event
.circle
.circle-inner
.label
label #{tline}
time #{val+20}.03.2014
.time
.period
.label.first 11.30
.period
.label 12:00
.period
.label.last 13:50
.label 13:00
@import "nib"
body
margin: 5em;
font-family: Myriad Pro;
.timeline
position: relative;
padding: 1.5em 0 0.5em;
margin: 1em 0 1em 100px;
border: 1px solid #ddd;
border-width: 0 1px;
.starttime, .stoptime
position: absolute;
top: 0;
z-index: 10;
padding: 3px 5px 0;
color: #999;
white-space: nowrap;
display: block;
font-size: 13px;
.starttime
left: 0;
.stoptime
text-align: right;
right: 0;
.line
display: block;
list-style-type: none;
margin: .5em 0 0;
padding: 0;
height: 1em;
border-top: 4px solid green;
width: 100%;
position: relative;
h4
position: absolute;
right: 100%;
top: -0.6em;
width: 100px;
font-weight: normal;
font-size: 13px;
line-height: 1;
margin: 0 5px 0 0;
white-space:nowrap;
text-align: right;
.events
position: relative;
top: -.8em;
margin: 0 .5em;
.event
width: 1em;
height: 1em;
position: absolute;
top: 0
margin: 0 0 0 -.5em;
.circle
position: relative;
background: #fff;
border: 4px solid green;
width: 1em;
height: 1em;
border-radius: 50%;
.circle-inner
background: #fff;
width: 1em;
height: 1em;
border-radius: 50%;
position: absolute;
top: 0;
left: 0;
.label
display: none;
width: 10em;
font-size: 13px;
border: 3px solid green;
background: #fff;
border-radius: .5em
padding: .5em 1em;
text-align: center;
box-shadow 0 2px 2px #fff
position: absolute;
margin: -2px 0 0 -6em;
left: 50%;
top: 50%;
label
display: block;
font-size: 16px;
font-weight: bold;
margin: 0 0 5px 0;
&:hover
.circle
.circle-inner
z-index: 1010;
.label
display: block;
z-index: 1000;
&.checklist
border-color:blue;
.events .event
.circle
border-color:blue;
.label
border-color:blue;
&.liquid
border-color:#5eff00;
.events .event
.circle
border-color:#5eff00;
.label
border-color:#5eff00;
&.hms
border-color:red;
.events .event
.circle
border-color:red;
.label
border-color:red;
.time
position: absolute;
top: 0;
left: 0;
right: 0;
bottom: 0;
z-index: -1;
.period
position: absolute;
top: 0;
bottom: 0;
.label
font-size: 11px;
height: 13px;
line-height: 13px;
color: #aaa;
margin: 3px;
&.last
float: right;
&.first, &.last
color: #999;
font-size: 13px;
&:nth-child(even)
background: #fafafa;
border: 1px solid #f0f0f0;
border-width: 0 1px;
.timeline.static
.line.checklist .events .event
&:nth-child(1)
left: 0%
&:nth-child(2)
left: 30%
&:nth-child(3)
left: 50%
&:nth-child(4)
left: 70%
&:nth-child(5)
left: 90%
.line.liquid .events .event
&:nth-child(1)
left: 15%
&:nth-child(2)
left: 25%
&:nth-child(3)
left: 60%
&:nth-child(4)
left: 70%
&:nth-child(5)
left: 85%
.line.hms .events .event
&:nth-child(1)
left: 5%
&:nth-child(2)
left: 20%
&:nth-child(3)
left: 55%
&:nth-child(4)
left: 72%
&:nth-child(5)
left: 87%
.time
.period
&:nth-child(1)
left: 0%
width: 10%
&:nth-child(2)
left: 10%
width: 62%
&:nth-child(3)
left: 72%
width: 28%
(function( $ ) {
$.fn.timeline = function( data ) {
return this.each(function() {
$el = $(this);
$el.addClass('timeline');
// calc ratio for event positions
var ratio = 100/(data.stop_time - data.start_time)
$.each(data.lines, function(i,line){
var lineTmpl = $('<div class="line"><h4>'+line.title+'</h4><div class="events"></div></div>').addClass("line "+ line.css).appendTo($el);
$.each(line.events, function(index,event){
var position = ((event.time - data.start_time)*ratio).toFixed(2);
var eventTmpl = $('<div class="event"><div class="circle"><div class="circle-inner"></div><div class="label"><label>'+event.title+'</label><time>'+(new Date(event.time).toLocaleString())+'</time></div></div></div>').appendTo($('.events', lineTmpl)).css('left',position+'%');
});
});
var timeTmpl = $('<div class="time">').appendTo($el);
var periodTmpl = $('<div class="period"><div class="label last">'+(new Date(data.stop_time).toLocaleString())+'</div><div class="label first">'+(new Date(data.start_time).toLocaleString())+'</div></div>').css({left:"0%", width:"100%"}).appendTo(timeTmpl);
});
};
var data = {
start_time: 90000,
stop_time: 120000,
lines: {
'checklists': {
title: 'Checklists',
css: 'checklist',
events: [
{
id: 1,
type: 'start_work',
time: 92000,
title: 'Start Work',
status: 'complete',
description: 'O-la-la'
},
{
id: 2,
type: 'vehicle',
time: 95000,
title: 'Vehicle',
status: 'complete',
description: 'O-la-la'
},
{
id: 3,
type: 'fuel',
time: 101500,
title: 'Vehicle',
status: 'resolve',
description: 'O-la-la'
},
{
id: 4,
type: 'trailer_pickup',
time: 105000,
title: 'Trailer Pickup',
status: 'complete',
description: 'O-la-la'
},
{
id: 5,
type: 'hms',
time: 107000,
title: 'Danger situation',
status: 'alert',
description: 'O-la-la'
},
{
id: 6,
type: 'trailer_delivery',
time: 110000,
title: 'Trailer delivery ',
status: 'complete',
description: 'O-la-la'
}
]
},
'liquids': {
title: 'Fuel Filling',
css: 'liquid',
events: [
{
id: 1,
type: 'start_work',
time: 90500,
title: 'Start Work',
status: 'complete',
description: 'O-la-la'
},
{
id: 2,
type: 'vehicle',
time: 96000,
title: 'Vehicle',
status: 'complete',
description: 'O-la-la'
},
{
id: 3,
type: 'fuel',
time: 98000,
title: 'Vehicle',
status: 'resolve',
description: 'O-la-la'
},
{
id: 4,
type: 'trailer_pickup',
time: 103000,
title: 'Trailer Pickup',
status: 'complete',
description: 'O-la-la'
},
{
id: 5,
type: 'hms',
time: 105000,
title: 'Danger situation',
status: 'alert',
description: 'O-la-la'
},
{
id: 6,
type: 'trailer_delivery',
time: 118000,
title: 'Trailer delivery ',
status: 'complete',
description: 'O-la-la'
}
]
},
'hms': {
title: 'Alerts',
css: 'hms',
events: [
{
id: 1,
type: 'start_work',
time: 100000,
title: 'Start Work',
status: 'complete',
description: 'O-la-la'
},
{
id: 2,
type: 'vehicle',
time: 115000,
title: 'Vehicle',
status: 'complete',
description: 'O-la-la'
}
]
}
}
};
$('.tl').timeline(data);
}( jQuery ));
Also see: Tab Triggers