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.
<!-- in a wrapping container include a div.card used to design the card -->
<div class="container">
<div class="card">
<!-- in the card display a header and a div each for each option -->
<h2>As you evaluate your site, consider if your content is:</h2>
<div class="card__option">
<!-- for each option include a div in which to include the description and a span used to display a + sign, to remark the toggle-able nature of the option -->
<div class="card__option--description">
<!-- for the description, include a term with dt element and an illustration of said term with a dd element -->
<dl>
<dt>
perceivable
</dt>
<dd>
Can people know that your cotent exists with more than one sense?
</dd>
</dl>
</div>
<span class="card__option--toggle">+</span>
</div>
<div class="card__option">
<div class="card__option--description">
<dl>
<dt>
understandable
</dt>
<dd>
Can users take in and comprehend the information in a variety of ways?
</dd>
</dl>
</div>
<span class="card__option--toggle">+</span>
</div>
<div class="card__option">
<div class="card__option--description">
<dl>
<dt>
operable
</dt>
<dd>
Can users interact with and navigate your website?
</dd>
</dl>
</div>
<span class="card__option--toggle">+</span>
</div>
<div class="card__option">
<div class="card__option--description">
<dl>
<dt>
robust
</dt>
<dd>
Can people access your site using various browsers, operating systems, and assistive tools?
</dd>
</dl>
</div>
<span class="card__option--toggle">+</span>
</div>
</div><!-- close div.card -->
</div><!-- close div.container -->
@import url('https://fonts.googleapis.com/css?family=Open+Sans');
font-main = 'Open Sans', sans-serif
black = #252525
green = #84BC45
*
box-sizing border-box
margin 0
padding 0
body
min-height 100vh
width 100%
font-family font-main
color black
background green
div.container
display flex
justify-content center
align-items center
min-height 100vh
padding 1rem 2rem
div.card
background #fff
height 100vh
width (@height * 0.8)
filter drop-shadow(0 1px 5px rgba(black, 0.3))
// transition the card into view
animation slideIn 0.3s 0.3s ease-out both
// display the contents of the div.card in a single column layout
display flex
flex-direction column
h2, div.card__option
// set the header and div(s) element to each cover a portion of the card
flex-grow 1
padding 2rem
h2
font-weight 300
div.card__option
// lay the div containing the text and the span containing the plus + sign in a row
display flex
align-items center
justify-content space-between
cursor pointer
// set transition for the change in background, prompted in the JS script
transition all 0.3s ease
span.card__option--toggle
font-size 2rem
font-weight bold
div.card__option--description
dl
// in a dl element, dt and dd element are already displayed vertically one after the other
// no need to specify further layout properties (like flex)
dt
font-weight bold
font-size 1.15rem
letter-spacing 0.05rem
text-transform uppercase
margin 0.2rem 0
dd
font-size 1.1rem
// by default hide the element
opacity 0
visibility hidden
// set height to 0 to allow for the dt element to be centered horizontally in the parent div
// otherwise, the element occupies space, even if not displayed on screen
height 0
&.active
// define a class which transitions the dd element into view (through JS instructions)
opacity 1
visibility visible
height 100%
// set transition only to the class to prevent the transition from occurring evenly as the class is added and removed
// this way the transition is set only when the class is added
// additionally, transition opacity with a delay, giving the time to the browser to accommodate the space necessary for the dd element
transition visibility 0.3s ease, opacity 0.3s 0.2s ease
// define the animation for the div.card element
@keyframes slideIn
0%
opacity 0
transform translateX(-20%)
100%
opacity 1
transform translateX(0)
// target all div containing the options
const cardOptions = document.querySelectorAll(".container .card .card__option");
// target all dd elements
const cardOptionsDescriptions = document.querySelectorAll(".container .card .card__option dl dd");
// target all span elements
const cardOptionsSpans = document.querySelectorAll(".container .card .card__option span");
// listen for a click event on each div containing each option, at which point call a function which displays the description of the clicked option
cardOptions.forEach(cardOption => {
cardOption.addEventListener("click", handleClick);
});
// create a function which takes as argument the (click) event and calls a function to display the correct option
function handleClick(e) {
// pass as argument the HTML node actually clicked (this may be the div.card__option, but also one of its nested items, such as the dt, or span elements nested within)
displayOption(e.target);
}
function displayOption(targetClick) {
// store in a variable the clicked element, and update it in a loop in order to find the parent div.card__option
let target = targetClick;
// until the target is not the parent div.card__option (technically until the element contains a class of .card__option)
while(!target.classList.contains("card__option")) {
// update the element to go up a node
target = target.parentNode;
}
// target the description element of the clicked div.card__option
let descriptionTarget = target.querySelector("dd");
// target the span element of the clicked div.card__option
let spanTarget = target.querySelector("span");
// if the dd element already has a class of active, remove it
// additionally reset the background of the parent container and add the plus sign + back
if(descriptionTarget.classList.contains("active")) {
target.style.background = "none";
descriptionTarget.classList.remove("active");
spanTarget.textContent = "+";
}
// otherwise call a function to remove the class of active from all options and add it exclusively to the only div.card__option
// additionally, style the parent container by changing its background and remove the plus sign from the nested span
else {
removeOptions();
target.style.background = "rgba(0,200,0,0.2)";
descriptionTarget.classList.add("active");
spanTarget.textContent = " ";
}
}
// create a function which removes the class of active from all dd elements
// additionally reset the background of the parent container and restore the plus sign + on all span elements
function removeOptions() {
cardOptions.forEach(cardOption => cardOption.style.background = "none");
cardOptionsSpans.forEach(cardOptionsSpan => cardOptionsSpan.textContent = "+");
cardOptionsDescriptions.forEach(cardOptionsDescription => cardOptionsDescription.classList.remove("active"));
}
Also see: Tab Triggers