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.
<!-- THE CHALLENGE: -->
<!-- 1. recreate version 3 (https://codepen.io/cjl750/pen/mXbMyo) with no javascript whatsoever
2. make code as abstract as possible (e.g., trying to calc positions that would work with any number of dots instead of hard-coding the container width as we do in our media queries)
3. highest browser support possible -->
<!-- Bonus points: turn v3's pseudo content into actual element content, so it's accessible to screen readers, search engines, etc. -->
<h1>Notable inventions, <span>1910–2000</span></h1>
<div class="flex-parent">
<div class="input-flex-container">
<input type="radio" name="timeline-dot" data-description="1910">
<div class="dot-info" data-description="1910">
<span class="year">1910</span>
<span class="label">headset</span>
</div>
<input type="radio" name="timeline-dot" data-description="1920">
<div class="dot-info" data-description="1920">
<span class="year">1920</span>
<span class="label">jungle gym</span>
</div>
<input type="radio" name="timeline-dot" data-description="1930" checked>
<div class="dot-info" data-description="1930">
<span class="year">1930</span>
<span class="label">chocolate chip cookie</span>
</div>
<input type="radio" name="timeline-dot" data-description="1940">
<div class="dot-info" data-description="1940">
<span class="year">1940</span>
<span class="label">Jeep</span>
</div>
<input type="radio" name="timeline-dot" data-description="1950">
<div class="dot-info" data-description="1950">
<span class="year">1950</span>
<span class="label">leaf blower</span>
</div>
<input type="radio" name="timeline-dot" data-description="1960">
<div class="dot-info" data-description="1960">
<span class="year">1960</span>
<span class="label">magnetic stripe card</span>
</div>
<input type="radio" name="timeline-dot" data-description="1970">
<div class="dot-info" data-description="1970">
<span class="year">1970</span>
<span class="label">wireless LAN</span>
</div>
<input type="radio" name="timeline-dot" data-description="1980">
<div class="dot-info" data-description="1980">
<span class="year">1980</span>
<span class="label">flash memory</span>
</div>
<input type="radio" name="timeline-dot" data-description="1990">
<div class="dot-info" data-description="1990">
<span class="year">1990</span>
<span class="label">World Wide Web</span>
</div>
<input type="radio" name="timeline-dot" data-description="2000">
<div class="dot-info" data-description="2000">
<span class="year">2000</span>
<span class="label">Google AdWords</span>
</div>
<div id="timeline-descriptions-wrapper">
<p data-description="1910">And future Call of Duty players would thank them.</p>
<p data-description="1920">Because every kid should get to be Tarzan for a day.</p>
<p data-description="1930">And the world rejoiced.</p>
<p data-description="1940">Because building roads is inconvenient.</p>
<p data-description="1950">Ain’t nobody got time to rake.</p>
<p data-description="1960">Because paper currency is for noobs.</p>
<p data-description="1970">Nobody likes cords. Nobody.</p>
<p data-description="1980">Brighter than glow memory.</p>
<p data-description="1990">To capitalize on an as-yet nascent market for cat photos.</p>
<p data-description="2000">Because organic search rankings take work.</p>
</div>
</div>
</div>
<div style="position: absolute; bottom: 15px; right: 10px; font-size: 12px">
<a href="https://codepen.io/cjl750/pen/mXbMyo" target="_blank">based off of version 3</a></div>
$numDots: 20
$parentWidthBase: 0.8
$parentWidth: $parentWidthBase * 100vw
$parentMaxWidth: 1000px
$dotWidth: 25px
$active: #2C3E50
$inactive: #AEB6BF
html
height: 100%
body
min-height: 100%
body
font-family: 'Quicksand', sans-serif
font-weight: 500
color: #424949
background-color: #ECF0F1
padding: 0 25px
display: flex
flex-direction: column
position: relative
h1
text-align: center
height: 38px
margin: 60px 0
span
white-space: nowrap
.flex-parent
display: flex
flex-direction: column
justify-content: center
align-items: center
width: 100%
height: 100%
min-height: 500px
.input-flex-container
display: flex
justify-content: space-around
align-items: center
flex-wrap: wrap
width: $parentWidth
max-width: $parentMaxWidth
position: relative
z-index: 0
margin-left: calc((#{$parentWidth} - #{$dotWidth}) / #{$numDots}) //make up for offset of .dot-info
input
width: $dotWidth
height: $dotWidth
background-color: $active
position: relative
border-radius: 50%
display: block
-moz-appearance: none
-webkit-appearance: none
appearance: none
cursor: pointer
&:focus
outline: none
&::before, &::after
content: ''
display: block
position: absolute
z-index: -1
top: 50%
transform: translateY(-50%)
background-color: $active
width: $parentWidth / $numDots
height: 5px
max-width: $parentMaxWidth / $numDots
&::before
left: calc(#{-$parentWidth / $numDots} + #{$dotWidth / 2})
&::after
right: calc(#{-$parentWidth / $numDots} + #{$dotWidth / 2})
&:checked
background-color: $active
&::before
background-color: $active
&::after
background-color: $inactive
&:checked
~ input
&, &::before, &::after
background-color: $inactive
+ .dot-info
span
font-size: 13px
font-weight: bold
.dot-info
width: $dotWidth
height: $dotWidth
display: block
// background-color: red
visibility: hidden
position: relative
z-index: -1
//position each span on top of the dot immediately before it; -1px at the end is just fudging the numbers for rounding error
left: calc((((#{$parentWidth} - #{$dotWidth}) / #{$numDots}) * -1) - 1px)
span
visibility: visible
position: absolute
font-size: 12px
&.year
bottom: -30px
left: 50%
transform: translateX(-50%)
&.label
top: -65px
left: 0
transform: rotateZ(-45deg)
width: 70px
text-indent: -10px
#timeline-descriptions-wrapper
width: 100%
margin-top: 140px
font-size: 22px
font-weight: 400
margin-left: calc((-#{$parentWidth} - #{$dotWidth}) / #{$numDots}) //make up for offset of .dot-info
p
margin-top: 0
display: none
// magic shenanigans
$descriptions: '1910', '1920', '1930', '1940', '1950', '1960', '1970', '1980', '1990', '2000'
@each $desc in $descriptions
input[data-description="#{$desc}"]:checked ~ #timeline-descriptions-wrapper
p[data-description="#{$desc}"]
display: block
@media (min-width: $parentMaxWidth / $parentWidthBase)
.input-flex-container
margin-left: #{($parentMaxWidth / $numDots) + ($dotWidth / 2)}
input
&::before
left: #{-($parentMaxWidth / $numDots) + ($dotWidth / 2)}
&::after
right: #{-($parentMaxWidth / $numDots) + ($dotWidth / 2)}
.dot-info
left: calc((((#{$parentMaxWidth} - #{$dotWidth}) / #{$numDots}) * -1) - 1px)
#timeline-descriptions-wrapper
margin-left: #{-($parentMaxWidth / $numDots) + ($dotWidth / 2)}
@media (max-width: 630px)
.flex-parent
justify-content: initial
.input-flex-container
flex-wrap: wrap
justify-content: center
width: 400px
height: auto
margin-top: 15vh
margin-left: 0
padding-bottom: 30px
input, .dot-info
width: 60px
height: 60px
margin: 0 10px 50px
input
background-color: transparent !important
z-index: 1
&::before, &::after
content: none
&:checked
+ .dot-info
background-color: $active
span
&.year
font-size: 14px
&.label
font-size: 12px
.dot-info
visibility: visible
border-radius: 50%
z-index: 0 // position behind input, so input remains clickable
left: 0
margin-left: -70px
background-color: $inactive
span
&.year
top: 0
left: 0
transform: none
width: 100%
height: 100%
display: flex
justify-content: center
align-items: center
color: #ECF0F1
&.label
top: calc(100% + 5px)
left: 50%
transform: translateX(-50%)
text-indent: 0
text-align: center
#timeline-descriptions-wrapper
margin-top: 30px
margin-left: 0
text-align: center
@media (max-width: 480px)
.input-flex-container
width: 340px
@media (max-width: 400px)
.input-flex-container
width: 300px
Also see: Tab Triggers