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.
<div class="button-container">
<button type="button" data-modal-id="my-modal" class="launch">Trailer Embed</button>
<button type="button" data-modal-id="my-other-modal" class="launch">Launch second Modal</button>
</div>
<div class="modal-container" id="modal-container">
<div class="modal" id="my-modal">
<iframe width="560" height="315" src="https://www.youtube.com/embed/XFYWazblaUA" frameborder="0" allow="autoplay; encrypted-media" allowfullscreen></iframe>
<button type="button" class="close">
<svg width="13px" height="13px" viewBox="0 0 13 13" version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink">
<!-- Generator: Sketch 48.2 (47327) - http://www.bohemiancoding.com/sketch -->
<desc>Created with Sketch.</desc>
<defs></defs>
<g id="Page-1" stroke="none" stroke-width="1" fill="none" fill-rule="evenodd">
<g id="Close" transform="translate(-29.000000, -47.000000)" fill="#D8D8D8">
<g id="Close-X-2" transform="translate(29.000000, 47.000000)">
<path d="M6.36396103,4.94974747 L11.3137085,1.77635684e-15 L12.7279221,1.41421356 L7.77817459,6.36396103 L12.7279221,11.3137085 L11.3137085,12.7279221 L6.36396103,7.77817459 L1.41421356,12.7279221 L-1.42108547e-14,11.3137085 L4.94974747,6.36396103 L-1.24344979e-14,1.41421356 L1.41421356,8.8817842e-16 L6.36396103,4.94974747 Z" id="Combined-Shape"></path>
</g>
</g>
</g>
</svg></button></div>
<div class="modal" id="my-other-modal">
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Duis porttitor felis ac urna elementum, ac tristique lacus malesuada. Integer tempor aliquam efficitur.</p>
<p>Donec eu est fermentum, consequat mauris id, laoreet nunc. Duis aliquam bibendum dolor at iaculis. Quisque id elementum erat. Nam sed suscipit metus. Sed a eros augue.</p>
<p>Mauris sed ante fermentum, malesuada risus vel, tincidunt augue. Proin venenatis erat vitae nibh scelerisque, sit amet molestie turpis ultrices.
</p>
<button type="button" class="close">
<svg width="13px" height="13px" viewBox="0 0 13 13" version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink">
<!-- Generator: Sketch 48.2 (47327) - http://www.bohemiancoding.com/sketch -->
<desc>Created with Sketch.</desc>
<defs></defs>
<g id="Page-1" stroke="none" stroke-width="1" fill="none" fill-rule="evenodd">
<g id="Close" transform="translate(-29.000000, -47.000000)" fill="#D8D8D8">
<g id="Close-X-2" transform="translate(29.000000, 47.000000)">
<path d="M6.36396103,4.94974747 L11.3137085,1.77635684e-15 L12.7279221,1.41421356 L7.77817459,6.36396103 L12.7279221,11.3137085 L11.3137085,12.7279221 L6.36396103,7.77817459 L1.41421356,12.7279221 L-1.42108547e-14,11.3137085 L4.94974747,6.36396103 L-1.24344979e-14,1.41421356 L1.41421356,8.8817842e-16 L6.36396103,4.94974747 Z" id="Combined-Shape"></path>
</g>
</g>
</g>
</svg></button></div>
</div>
<p>You should probably check out this <a target="_blank" href="https://codepen.io/bdnorris/pen/gOpbaxP">accessible modal codepen instead.</p>
$primary: #0288D1;
$secondary: #CFD8DC;
@mixin button-reset {
border: none;
background: none;
color: inherit;
padding: 0;
margin: 0;
font-family: inherit;
box-shadow: none;
}
body {
font-family: 'Fira Sans', sans-serif;
}
p {
line-height: 1.4;
text-align: center;
}
.button-container {
width: 100vw;
height: 80vh;
display: flex;
justify-content: center;
align-items: center;
}
button.launch {
@include button-reset;
padding: 0.666em 1em;
background-color: $primary;
color: white;
text-transform: uppercase;
letter-spacing: 0.1em;
margin: 1em;
border-radius: 6px;
}
.modal-container {
position: fixed;
left: 0;
right: 0;
top: 0;
bottom: 0;
background-color: rgba(0,0,0,0.2);
display: none;
z-index: 100;
// Safari issue fixes
overflow: auto;
-webkit-overflow-scrolling: touch;
&.active {
display: flex;
justify-content: center;
align-items: center;
}
}
.modal {
display: none;
opacity: 0;
padding: 3em;
margin: auto;
background-color: white;
position: relative;
z-index: 101;
max-width: 70vw;
max-height: 70vh;
overflow: auto;
// Safari Issue fixes
-webkit-transform: translate3d(0,0,0);
&.active {
display: block;
opacity: 1;
animation: slide-in-fwd-top 0.4s cubic-bezier(0.250, 0.460, 0.450, 0.940) both;
}
button.close {
@include button-reset;
position: absolute;
top: 0.5em;
right: 0.5em;
padding: 0.5em;
}
}
/* ----------------------------------------------
* Generated by Animista on 2018-1-9 20:45:42
* w: http://animista.net, t: @cssanimista
* ---------------------------------------------- */
/**
* ----------------------------------------
* animation slide-in-fwd-top
* ----------------------------------------
*/
@keyframes slide-in-fwd-top {
0% {
transform: translateZ(-1400px) translateY(-800px);
opacity: 0;
}
100% {
transform: translateZ(0) translateY(0);
opacity: 1;
}
}
//https://css-tricks.com/snippets/javascript/loop-queryselectorall-matches/
// forEach method, could be shipped as part of an Object Literal/Module
function forEach(array, callback, scope) {
for (var i = 0; i < array.length; i++) {
callback.call(scope, i, array[i]); // passes back stuff we need
}
}
// Get all modal buttons into a node-list
var modalButtons = document.querySelectorAll("[data-modal-id]");
// Get all modals into a node-list
var allModals = document.querySelectorAll(".modal");
// Cache a reference to the modal container
var modalContainer = document.getElementById("modal-container");
// Add an event to the container to close
if (typeof modalContainer !== "undefined" && modalContainer) {
modalContainer.addEventListener("click", function(e) {
console.log(e.target);
console.log(this);
if (e.target === this) {
closeModal(this, "from screen");
} else {
// ignore click because it's not directly on the container screen
}
});
}
// run through all modal buttons and add event listeners
if (typeof modalButtons !== "undefined" && modalButtons) {
forEach(modalButtons, function(index, value) {
// get the data attribute id
let modalId = value.getAttribute("data-modal-id");
// add event listeners to each modal to run our function
value.addEventListener("click", function() {
handleModal(index, modalId);
});
});
}
if (typeof allModals !== "undefined" && allModals !== null) {
forEach(allModals, function(index, value) {
// cache a nodelist of the close button inside the modal
let button = value.querySelectorAll(".close");
// add event listeners to each close button inside the modals
button[0].addEventListener("click", function() {
closeModal(value, "button close");
});
});
}
function handleModal(i, id) {
// just in case, clear any other active modals
forEach(allModals, function(index, value) {
value.classList.remove("active");
if (allModals[index].id === id) {
allModals[index].classList.add("active");
}
});
// add an active class to the desired modal
// allModals[i].classList.add("active");
// add an active class to the container as well
modalContainer.classList.add("active");
}
function closeModal(modal, source) {
if (source === "from button") {
// if we're closing from a button, remove the active class from the surrounding modal
modal.path[1].classList.remove("active");
} else {
// otherwise, remove the active class from the container and ...
modalContainer.classList.remove("active");
forEach(allModals, function(index, value) {
// remove the active class from all modals
modal.classList.remove("active");
});
}
}
Also see: Tab Triggers