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.
<!-- title -->
<div class="box">
<h1 class="box__title">Modals</h1>
<p class="box__p">Click / Enter the buttons to open modals.</p>
</div>
<!-- /title -->
<!-- modal 1 -->
<div class="box">
<a href="#m1-o" class="link-1" id="m1-c">Modal 1</a>
<p class="box__info">Without Background</p>
<div class="modal-container" id="m1-o" style="--m-background: transparent;">
<div class="modal">
<h1 class="modal__title">Modal 1 Title</h1>
<p class="modal__text">Lorem ipsum dolor sit amet, consectetur adipisicing elit. Facilis ex dicta maiores libero minus obcaecati iste optio, eius labore repellendus.</p>
<button class="modal__btn">Button →</button>
<a href="#m1-c" class="link-2"></a>
</div>
</div>
</div>
<!-- /modal 1 -->
<!-- modal 2 -->
<div class="box">
<a href="#m2-o" class="link-1" id="m2-c">Modal 2</a>
<p class="box__info">With Background (Opacity .4)</p>
<div class="modal-container" id="m2-o" style="--m-background: hsla(0, 0%, 0%, .4);">
<div class="modal">
<h1 class="modal__title">Modal 2 Title</h1>
<p class="modal__text">Lorem ipsum dolor sit amet, consectetur adipisicing elit. Facilis ex dicta maiores libero minus obcaecati iste optio, eius labore repellendus.</p>
<button class="modal__btn">Button →</button>
<button class="modal__btn">Button →</button>
<a href="#m2-c" class="link-2"></a>
</div>
</div>
</div>
<!-- /modal 2 -->
<!-- modal 3 -->
<div class="box">
<a href="#m3-o" class="link-1" id="m3-c">Modal 3</a>
<p class="box__info">With Background Full Opacity</p>
<div class="modal-container" id="m3-o" style="--m-background: var(--global-background);">
<div class="modal" style="--m-shadow: 0 0 10rem 0">
<h1 class="modal__title">Modal 3 Title</h1>
<p class="modal__text">Lorem ipsum dolor sit amet, consectetur adipisicing elit. Facilis ex dicta maiores libero minus obcaecati iste optio, eius labore repellendus.</p>
<button class="modal__btn">Button →</button>
<button class="modal__btn">Button →</button>
<a href="#m3-c" class="link-2"></a>
</div>
</div>
</div>
<!-- /modal 3 -->
<!-- Note(s) -->
<div class="box">
<p class="box__note">For users using a mouse, they have to close the modal to be able to click on something else, but for users using a keyboard, they can navigate outside of the modal (when modal is opened). Still need JavaScript for certain <em>things</em> but the pen is about what we can achieve using CSS only, so... and about why I gave the open modal link a unique id(m$-c) is because, when our users will click/enter the close link, I want to send them back to that open link rather than sending them on the top of the page(by setting href="#"). <em>Might</em> be not an issue for users using a mouse <em>(if I am the user, yes it definitely is)</em>, but for users using the keyboard, it definitely is; me just preventing that.</p>
</div>
<!-- /Note(s) -->
<a href="https://abubakersaeed.netlify.app/designs/d8-modals" class="abs-site-link" rel="nofollow noreferrer" target="_blank">abs/designs/d8-modals</a>
/*
================================
Best Viewed In Full Page
================================
*/
/* Because I'm using the fixed position for modals, if the screen height is small then you would not be able to see a full modal that's why it's recommended that you see this pen in full-page and not on editor view. */
/* defaults */
*,
*::after,
*::before {
margin: 0;
padding: 0;
box-sizing: border-box;
}
html {
font-size: 62.5%;
}
body {
--light: hsl(220, 50%, 90%);
--primary: hsl(255, 30%, 55%);
--focus: hsl(210, 90%, 50%);
--border-color: hsla(0, 0%, 100%, .2);
--global-background: hsl(220, 25%, 10%);
--background: linear-gradient(to right, hsl(210, 30%, 20%), hsl(255, 30%, 25%));
--shadow-1: hsla(236, 50%, 50%, .3);
--shadow-2: hsla(236, 50%, 50%, .4);
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Open Sans', sans-serif;
color: var(--light);
background: var(--global-background);
}
a,
a:link {
font-family: inherit;
text-decoration: none;
}
a:focus {
outline: none;
}
button::-moz-focus-inner {
border: 0;
}
/* box */
.box {
display: flex;
flex-direction: column;
justify-content: center;
align-items: center;
height: 100vh;
padding: 0 4rem 2rem;
}
.box:not(:first-child) {
height: 45rem;
}
.box__title {
font-size: 10rem;
font-weight: normal;
letter-spacing: .8rem;
margin-bottom: 2.6rem;
}
.box__title::first-letter {
color: var(--primary);
}
.box__p,
.box__info,
.box__note {
font-size: 1.6rem;
}
.box__info {
margin-top: 6rem;
}
.box__note {
line-height: 2;
}
/* modal */
.modal-container {
position: fixed;
top: 0;
left: 0;
z-index: 10;
display: none;
justify-content: center;
align-items: center;
width: 100%;
height: 100%;
/* --m-background is set as inline style */
background: var(--m-background);
}
/* using :target */
/*
when users will click/enter button(link) browser will add a #id in a url and when that happens we'll show our users the modal that contains that id.
*/
.modal-container:target {
display: flex;
}
.modal {
width: 60rem;
padding: 4rem 2rem;
border-radius: .8rem;
color: var(--light);
background: var(--background);
box-shadow: var(--m-shadow, .4rem .4rem 10.2rem .2rem) var(--shadow-1);
position: relative;
overflow: hidden;
}
.modal__title {
font-size: 3.2rem;
}
.modal__text {
padding: 0 4rem;
margin-top: 4rem;
font-size: 1.6rem;
line-height: 2;
}
.modal__btn {
margin-top: 4rem;
padding: 1rem 1.6rem;
border: 1px solid var(--border-color);
border-radius: 100rem;
color: inherit;
background: transparent;
font-size: 1.4rem;
font-family: inherit;
letter-spacing: .2rem;
transition: .2s;
cursor: pointer;
}
.modal__btn:nth-of-type(1) {
margin-right: 1rem;
}
.modal__btn:hover,
.modal__btn:focus {
background: var(--focus);
border-color: var(--focus);
transform: translateY(-.2rem);
}
/* link-... */
.link-1 {
font-size: 1.8rem;
color: var(--light);
background: var(--background);
box-shadow: .4rem .4rem 2.4rem .2rem var(--shadow-1);
border-radius: 100rem;
padding: 1.4rem 3.2rem;
transition: .2s;
}
.link-1:hover,
.link-1:focus {
transform: translateY(-.2rem);
box-shadow: 0 0 4.4rem .2rem var(--shadow-2);
}
.link-1:focus {
box-shadow:
0 0 4.4rem .2rem var(--shadow-2),
0 0 0 .4rem var(--global-background),
0 0 0 .5rem var(--focus);
}
.link-2 {
width: 4rem;
height: 4rem;
border: 1px solid var(--border-color);
border-radius: 100rem;
color: inherit;
font-size: 2.2rem;
position: absolute;
top: 2rem;
right: 2rem;
display: flex;
justify-content: center;
align-items: center;
transition: .2s;
}
.link-2::before {
content: '×';
transform: translateY(-.1rem);
}
.link-2:hover,
.link-2:focus {
background: var(--focus);
border-color: var(--focus);
transform: translateY(-.2rem);
}
.abs-site-link {
position: fixed;
bottom: 20px;
left: 20px;
color: hsla(0, 0%, 1000%, .6);
font-size: 1.6rem;
}
// @AbubakerSaeed96 (twitter)
// abubakersaeed.netlify.com
// =========================
// Suppose Javascript is off and there is some important content we want our users to see via modal, we can use this approach.
// Thank You for Viewing.
// CSS Modal v1:
// That version is in light mode and has little different design than this one
// https://codepen.io/AbubakerSaeed/pen/qBWRGNm
Also see: Tab Triggers