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.
Building a Vertical Timeline With CSS and a Touch of JavaScript
original by <a href="https://webdesign.tutsplus.com/tutorials/building-a-vertical-timeline-with-css-and-a-touch-of-javascript--cms-26528"> George Martsoukos on 24 May 2016</a>
Original codepen
<a href="https://codepen.io/tutsplus/details/QNeJgR"> is here </a>
<br>
scroll and resize to view effetcs
<div class="timeline2">
<ul>
<li>
<div>
<time>1934</time> At vero eos et accusamus et iusto odio dignissimos ducimus qui blanditiis praesentium At vero eos et accusamus et iusto odio dignissimos ducimus qui blanditiis praesentium
</div>
<span class="time">
<span>JUN, 17<sup>th</sup></span>
<span>12:00 AM</span>
</span>
</li>
<li>
<div>
<time>1937</time> Proin quam velit, efficitur vel neque vitae, rhoncus commodo mi. Suspendisse finibus mauris et bibendum molestie. Aenean ex augue, varius et pulvinar in, pretium non nisi.
</div>
<span class="time">
<span>JUN, 29<sup>th</sup></span>
<span>11:36 AM</span>
</span>
</li>
<li>
<div>
<time>1940</time> Proin iaculis, nibh eget efficitur varius, libero tellus porta dolor, at pulvinar tortor ex eget ligula. Integer eu dapibus arcu, sit amet sollicitudin eros.
</div>
<span class="time">
<span>Jul, 1<sup>st</sup></span>
<span>10:30 AM</span>
</span>
</li>
<li>
<div>
<time>1943</time> In mattis elit vitae odio posuere, nec maximus massa varius. Suspendisse varius volutpat mattis. Vestibulum id magna est.
</div>
<span class="time">
<span>Jul, 2<sup>nd</sup></span>
<span>12:30 PM</span>
</span>
</li>
<li>
<div>
<time>1946</time> In mattis elit vitae odio posuere, nec maximus massa varius. Suspendisse varius volutpat mattis. Vestibulum id magna est.
</div>
<span class="time">
<span>Jul, 3<sup>rd</sup></span>
<span>01:30 PM</span>
</span>
</li>
<li>
<div>
<time>1956</time> In mattis elit vitae odio posuere, nec maximus massa varius. Suspendisse varius volutpat mattis. Vestibulum id magna est.
</div>
<span class="time">
<span>Jul, 4<sup>th</sup></span>
<span>01:30 PM</span>
</span>
</li>
<li>
<div>
<time>1957</time> In mattis elit vitae odio posuere, nec maximus massa varius. Suspendisse varius volutpat mattis. Vestibulum id magna est.
</div>
<span class="time">
<span>Jul, 5<sup>th</sup></span>
<span>01:30 PM</span>
</span>
</li>
<li>
<div>
<time>1967</time> Aenean condimentum odio a bibendum rhoncus. Ut mauris felis, volutpat eget porta faucibus, euismod quis ante.
</div>
<span class="time">
<span>Jul, 6<sup>th</sup></span>
<span>01:30 PM</span>
</span>
</li>
<li>
<div>
<time>1977</time> Vestibulum porttitor lorem sed pharetra dignissim. Nulla maximus, dui a tristique iaculis, quam dolor convallis enim, non dignissim ligula ipsum a turpis.
</div>
<span class="time">
<span>Jul, 7<sup>th</sup></span>
<span>01:30 PM</span>
</span>
</li>
<li>
<div>
<time>1985</time> In mattis elit vitae odio posuere, nec maximus massa varius. Suspendisse varius volutpat mattis. Vestibulum id magna est.
</div>
<span class="time">
<span>Aug, 1<sup>st</sup></span>
<span>01:30 PM</span>
</span>
</li>
<li>
<div>
<time>2000</time> In mattis elit vitae odio posuere, nec maximus massa varius. Suspendisse varius volutpat mattis. Vestibulum id magna est.
</div>
<span class="time">
<span>Aug, 2<sup>nd</sup></span>
<span>01:30 PM</span>
</span>
</li>
<li>
<div>
<time>2005</time> In mattis elit vitae odio posuere, nec maximus massa varius. Suspendisse varius volutpat mattis. Vestibulum id magna est.
</div>
<span class="time">
<span>Aug, 3<sup>rd</sup></span>
<span>01:30 PM</span>
</span>
</li>
</ul>
</div>
/* TIMELINE
–––––––––––––––––––––––––––––––––––––––––––––––––– */
.timeline2 {
overflow-y: scroll;
overflow-x: hidden;
height: 550px;
top: calc(100%-600px);
position: relative;
scroll-behavior: smooth ;
}
.timeline2 *, .timeline2 *::before, .timeline2 *::after {
font: normal 16px/1.5 "Helvetica Neue", sans-serif;
color: #fff;
margin: 0;
padding: 0;
box-sizing: border-box;
}
.timeline2::-webkit-scrollbar {
width: 12px;
background-color: #F5F5F5;
}
.timeline2::-webkit-scrollbar-track {
-webkit-box-shadow: inset 0 0 6px rgba(0,0,0,0.3);
border-radius: 10px;
background-color: #F5F5F5;
}
.timeline2::-webkit-scrollbar-thumb {
border-radius: 10px;
-webkit-box-shadow: inset 0 0 6px rgba(0,0,0,.3);
background-color: #555;
}
.timeline2 ul {
background: #456990;
/* padding: 50px 0; */
}
.timeline2 ul li {
list-style-type: none;
position: relative;
width: 2px;/* width: 6px; */
margin: 0 auto;
padding-top: 10px;/* 50px; */
padding-bottom: 10px;/* padding-bottom: 20px; = center padding-bottom: 10px; = center */
background: #fff; /* background: black; */
border-left: 3px double white;
}
.timeline2 ul li::after {
content: '';
position: absolute;
left: 50%;
top: 30px; /* bottom: 0; bottom: 50%;=center top: 30px;=top */
transform: translateX(-55%);/* transform: translateX(-50%); */
-webkit-transform: translateX(-55%);
width: 30px;
height: 30px;
border-radius: 50%;
background: inherit;
border: 2px solid #03A9F4;
}
.timeline2 ul li div {
position: relative;
bottom: 0;
width: 400px;
padding: 15px;
background: #03A9F4;
}
.timeline2 ul li div::before {
content: '';
position: absolute;
top: 20px; /* bottom: 7px; bottom: 50%;=center top: 20px;=top */
width: 0;
height: 0;
border-style: solid;
}
.timeline2 ul li:nth-child(odd) div {
left: 45px;
}
.timeline2 ul li:nth-child(odd) div::before {
left: -15px;
border-width: 16px 16px 16px 0;/* border-width: 8px 16px 8px 0; */
border-color: transparent #03A9F4 transparent transparent;
}
.timeline2 ul li:nth-child(even) div {
left: -439px;
}
.timeline2 ul li:nth-child(even) div::before {
right: -15px;
border-width: 16px 0 16px 16px; /* border-width: 8px 0 8px 16px; */
border-color: transparent transparent transparent #03A9F4;
}
.timeline2 ul li:nth-child(odd) .time {
position: absolute;
top: 20px;
left: -100px;
width: 90px;
}
.timeline2 ul li:nth-child(even) .time {
position: absolute;
top: 20px;
right: -120px;
width: 90px;
}
.timeline2 time {
display: block;
font-size: 1.2rem;
font-weight: bold;
margin-bottom: 8px;
}
/* EFFECTS
–––––––––––––––––––––––––––––––––––––––––––––––––– */
.timeline2 ul li::after {
transition: background .5s ease-in-out;
-webkit-transition: background .5s ease-in-out;
}
.timeline2 ul li.in-view::after {
background: #03A9F4;
border: 2px solid white;
}
.timeline2 ul li div {
visibility: hidden;
opacity: 0;
transition: all .5s ease-in-out;
-webkit-transition: all .5s ease-in-out;
}
.timeline2 ul li:nth-child(odd) div {
transform: translate3d(200px, 0, 0);
-webkit-transform: translate(200px, 0, 0);
}
.timeline2 ul li:nth-child(even) div {
transform: translate3d(-200px, 0, 0);
-webkit-transform: translate(-200px, 0, 0);
}
.timeline2 ul li.in-view div {
transform: none;
-webkit-transform: none;
visibility: visible;
opacity: 1;
/* disabled when arrow is on top position
border-radius: 10px;
*/
}
.timeline2 ul li .time {
transition: all .5s ease-in-out;
-webkit-transition: all .5s ease-in-out;
transform: rotate(-90deg);
-webkit-transform:rotate(270deg);
}
.timeline2 ul li.in-view .time {
transform: rotate(0deg);
-webkit-transform:rotate(0deg);
}
/* GENERAL MEDIA QUERIES
–––––––––––––––––––––––––––––––––––––––––––––––––– */
@media screen and (max-width: 900px) {
.timeline2 ul li div {
width: 250px;
}
.timeline2 ul li:nth-child(even) div {
left: -289px;
/*250+45-6*/
}
}
@media screen and (max-width: 600px) {
.timeline2 ul li {
margin-left: 20px;
}
.timeline2 ul li div {
width: calc(100vw - 120px);
}
.timeline2 ul li:nth-child(even) div {
left: 45px;
}
.timeline2 ul li:nth-child(even) div::before {
left: -15px;
border-width: 16px 16px 16px 0; /* border-width: 8px 16px 8px 0; */
border-color: transparent #03A9F4 transparent transparent;
}
.timeline2 ul li:nth-child(odd) .time {
position: absolute;
top: 60px;
left: -23px;
width: 90px;
/*
transform: rotate(-90deg);
-webkit-transform:rotate(270deg);
*/
transform: rotate(0deg);
-webkit-transform:rotate(0deg);
}
.timeline2 ul li:nth-child(even) .time {
position: absolute;
top: 60px;
right: -67px;
width: 90px;
/*
transform: rotate(-90deg);
-webkit-transform:rotate(270deg);
*/
transform: rotate(0deg);
-webkit-transform:rotate(0deg);
}
.timeline2 ul li.in-view:nth-child(odd) .time {
transform: rotate(-90deg);
-webkit-transform:rotate(270deg);
}
.timeline2 ul li.in-view:nth-child(even) .time {
transform: rotate(-90deg);
-webkit-transform:rotate(270deg);
}
}
(function() {
'use strict';
// define variables
var timelines= document.querySelectorAll('.timeline2');
function debounce(func, wait, immediate) {
var timeout;
return function() {
var context = this, args = arguments;
var later = function() {
timeout = null;
if (!immediate) func.apply(context, args);
};
var callNow = immediate && !timeout;
clearTimeout(timeout);
timeout = setTimeout(later, wait);
if (callNow) func.apply(context, args);
};
}
function callbackFunc() {
var h,timeline, li,rect,parent_rect,i,items;
for(h=0;h<timelines.length;h++){
timeline=timelines[h];
parent_rect=timeline.getBoundingClientRect();
items = timeline.querySelectorAll(".timeline2 li");
for ( i = 0; i < items.length; i++) {
/*
if (isElementInViewport(items[i])) {
items[i].classList.add("in-view");
}
*/
li=items[i];
rect = li.getBoundingClientRect();
if( (rect.bottom<=(parent_rect.top+(rect.height/2) ) ) || (rect.top >=(parent_rect.bottom-(rect.height/2)) ) ){
//debugger;
//li.style['background']='red';
li.classList.remove("in-view");
}else{
//li.style['background']='white';
li.classList.add("in-view");
}
}
}
}
var updateLayout =debounce(function(e) {
// Does all the layout updating here
callbackFunc();
}, 500); // Maximum run of once per 500 milliseconds
// listen for events
window.addEventListener("load", callbackFunc);
window.addEventListener("resize", updateLayout);
window.addEventListener("scroll", callbackFunc);
for(var h=0;h<timelines.length;h++){
var timeline=timelines[h];
timeline.addEventListener("scroll",callbackFunc );
}
})();
Also see: Tab Triggers