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.
<main id="app">
<header>
<h1>Tailwind Outside Rounded Corners</h1>
<p>Simple outside corners using a <strong><code>radial mask</code></strong>, allowing the background to be
exposed without any need for fake background colors. <strong>
Even works with Gradients/Images!</strong></p>
<p>Also <a href="https://github.com/simeydotme/tailwind-rounded-out" target="_blank">available as a Tailwind Plugin</a></p>
</header>
<section>
<div class="top">
<div class="tab selected">
simple
</div>
<div class="tab">
outside
</div>
<div class="tab">
rounded
</div>
<div class="tab">
corners
</div>
</div>
<div class="bottom">
<div class="tab selected">
simple
</div>
<div class="tab">
outside
</div>
<div class="tab">
rounded
</div>
<div class="tab">
corners
</div>
</div>
</section>
<div class="inputs">
<input type="color" value="#ffffff" id="fg">
<input type="color" value="#1d1d29" id="bg">
<button id="gradient"></button>
<input type="range" id="size" min=4 max=32 value=16>
</div>
</main>
<!--
social icons
-->
<a class="social-icon codepen" href="https://codepen.io/simeydotme" title="view my codepens">
Made by Simey
</a>
<a class="social-icon twitter" href="https://twitter.com/simeydotme">
<svg viewBox="0 0 24 24">
<path stroke="none" d="M0 0h24v24H0z" fill="none"></path>
<path d="M22 4.01c-1 .49 -1.98 .689 -3 .99c-1.121 -1.265 -2.783 -1.335 -4.38 -.737s-2.643 2.06 -2.62 3.737v1c-3.245 .083 -6.135 -1.395 -8 -4c0 0 -4.182 7.433 4 11c-1.872 1.247 -3.739 2.088 -6 2c3.308 1.803 6.913 2.423 10.034 1.517c3.58 -1.04 6.522 -3.723 7.651 -7.742a13.84 13.84 0 0 0 .497 -3.753c-.002 -.249 1.51 -2.772 1.818 -4.013z"></path>
</svg>
</a>
<a class="social-icon github" href="https://github.com/simeydotme">
<svg viewBox="0 0 24 24">
<path stroke="none" d="M0 0h24v24H0z" fill="none"></path>
<path d="M9 19c-4.3 1.4 -4.3 -2.5 -6 -3m12 5v-3.5c0 -1 .1 -1.4 -.5 -2c2.8 -.3 5.5 -1.4 5.5 -6a4.6 4.6 0 0 0 -1.3 -3.2a4.2 4.2 0 0 0 -.1 -3.2s-1.1 -.3 -3.5 1.3a12.3 12.3 0 0 0 -6.2 0c-2.4 -1.6 -3.5 -1.3 -3.5 -1.3a4.2 4.2 0 0 0 -.1 3.2a4.6 4.6 0 0 0 -1.3 3.2c0 4.6 2.7 5.7 5.5 6c-.6 .6 -.6 1.2 -.5 2v3.5"></path>
</svg>
</a>
/*
comments / explanations below 👇
*/
#app {
--radius: 16px;
--height: max(48px, calc( var(--radius) * 2 ));
}
.tab {
height: var(--height);
border-radius: var(--radius) var(--radius) 0 0;
/*
these --height and --radius variables are not explicitly needed
for the effect, they could be hard-set into the css if you know you always
want your rounded corners to be the same size. I've used variables here so
you can edit them and see the dynamic change of the corners easily!
*/
position: relative; /* relative so we can position the corners */
}
.tab::after,
.tab::before {
/*
here's the magic.
- I set a background color of inherit to the :before and :after
= so it perfectly matches the parent it's set on
- I set a radial mask to cover the :before and :after perfectly
= with a little 0.25px buffer for sub-pixel anti-aliasing
- I make the mask 200% to cover the other edges of the :before and :after
- Then I position the mask in the bottom corner
*/
aspect-ratio: 1;
width: var(--radius, 20px);
/* the width of the :before/:after is the outer corner size */
background: inherit;
mask-image: radial-gradient(100% 100% at center, transparent calc(50% - 0.25px), black calc(50% + 0.25px));
/* the mask is flexible and scales with the width, no need to edit it */
mask-size: 200% 200%;
mask-position: 100% 100%;
pointer-events: none;
/*
this is just normal positioning of the :before and :after to
get them set at the bottom left of the parent container
*/
content: "";
position: absolute;
bottom: 0;
left: calc( var(--radius, 20px) * -1);
}
.tab::after {
/*
and for the other side, I simply flip the whole box horizontally
and position it at the end of the parent container
*/
scale: -1 1;
left: auto;
right: calc( var(--radius, 20px) * -1);
}
/*
just some extra styling for the top-tabs to show
the outside corners can be easily set on top (or sides)
*/
.top .tab {
border-radius: 0 0 var(--radius) var(--radius);
}
.top .tab::before,
.top .tab::after {
bottom: auto;
top: 0;
scale: 1 -1;
}
.top .tab::after {
bottom: auto;
top: 0;
scale: -1 -1;
}
/*
not important for the effect, just for demo purpose
*/
:root {
--h: 240;
--s: 18%;
--light: hsl(var(--h), var(--s), 95%);
--dark: hsl(var(--h), var(--s), 15%);
--fg: var(--light);
--bg: var(--dark);
--grad: url("data:image/svg+xml,%3Csvg viewBox='0 0 0 0' xmlns='http://www.w3.org/2000/svg'%3E%3Cfilter id='noiseFilter'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.65' numOctaves='3' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23noiseFilter)'/%3E%3C/svg%3E"), radial-gradient(circle at 68% 1%, hsla(253, 66%, 75%, 1) 7%, transparent 61%), radial-gradient(circle at 1% 48%, hsla(226, 66%, 63%, 1) 13%, transparent 54%), radial-gradient(circle at 58% 29%, hsla(359, 63%, 67%, 1) 19%, transparent 81%), radial-gradient(circle at 83% 79%, hsla(181, 88%, 59%, 1) 15%, transparent 61%), radial-gradient(circle at 85% 56%, hsla(293, 91%, 54%, 1) 0%, transparent 78%), radial-gradient(circle at 20% 43%, hsla(293, 89%, 59%, 1) 8%, transparent 55%), radial-gradient(circle at 63% 14%, hsla(197, 99%, 92%, 1) 9%, transparent 69%), radial-gradient(circle at 51% 27%, hsla(251, 96%, 90%, 1) 4%, transparent 50%), radial-gradient(circle at 26% 50%, hsla(270, 63%, 55%, 1) 20%, transparent 71%), radial-gradient(circle at 65% 83%, hsla(278, 99%, 97%, 1) 2%, transparent 90%);
/*
I'm only setting colors with variables here so that I can
easily change them with the color inputs and javascript in the
demo to demonstrate the flexibility.
The variables are not needed for the effect!
*/
}
section {
display: flex;
flex-direction: column;
justify-content: space-between;
overflow: hidden;
resize: horizontal;
background: var(--bg);
background-image: var(--img, var(--grad));
background-blend-mode: overlay, normal, normal, normal, normal, normal, normal, normal, normal, normal, normal;
background-size: cover;
border-radius: 12px;
padding-inline: 2em;
min-height: 200px;
}
section > div {
display: flex;
align-items: flex-end;
justify-content: space-around;
gap: 2px;
}
section > div.top {
align-items: flex-start;
}
.tab:not(section) {
min-width: 3em;
padding-inline: 2.5em;
transition: all 0.25s ease;
cursor: pointer;
display: flex;
justify-content: center;
align-items: center;
background-color: var(--fg);
color: var(--bg);
color: color-mix(in hsl, var(--fg), var(--bg) 50%);
}
.tab.selected {
z-index: 2;
height: calc(var(--height) + 4px);
}
.tab {
background-color: color-mix(in hsl, var(--fg), var(--bg) 30%);
&:hover {
background-color: color-mix(in hsl, var(--fg), var(--bg) 20%);
z-index: 1;
}
}
.inputs {
display: flex;
flex-wrap: wrap;
justify-content: center;
align-items: center;
gap: 20px;
}
#app {
display: grid;
grid-template-columns: 1fr;
grid-template-rows: max-content 200px 120px;
max-width: 600px;
margin: auto;
place-content: center;
row-gap: 2em;
text-align: center;
}
html, body {
display: grid;
grid-template: 1fr / 1fr;
min-height: 100%;
justify-content: center;
align-items: center;
background: var(--bg);
}
button {
height: 2.5em;
border: 6px solid white;
background: var(--grad);
border-radius: 100px;
&:hover,
&:focus {
box-shadow: none;
border-color: white;
}
}
input[type=color] {
max-width: 76px!important;
}
input[type=range] {
--bg: var(--light);
--fg: var(--dark);
}
header {
color: var(--light);
text-wrap: balance;
}
header p {
color: hsl(var(--h), var(--s), 60%);
}
header strong {
color: hsl(var(--h), var(--s), 90%);
}
#app {
--bor: hsl(var(--h), var(--s), 85%);
--bg: var(--dark);
--fg: var(--light);
--b: hsla(var(--h), var(--s), 100%, 1);
--svg: var(--fg);
}
const $app = document.querySelector("#app");
const $tabs = document.querySelectorAll(".tab");
const $fg = document.querySelector("#fg");
const $bg = document.querySelector("#bg");
const $g = document.querySelector("#gradient");
const $range = document.querySelector("#size");
$fg.addEventListener('input', (e) => {
$app.style.setProperty('--fg', e.target.value);
});
$bg.addEventListener('input', (e) => {
$app.style.setProperty('--bg', e.target.value);
});
$bg.addEventListener('click', (e) => {
$app.style.setProperty('--img', 'none');
});
$g.addEventListener('click', (e) => {
$app.style.setProperty('--img', 'var(--grad)');
});
$tabs.forEach((t) => {
t.addEventListener('click', () => {
$tabs.forEach( tt => {
tt.classList.remove("selected");
})
t.classList.add("selected");
})
})
$range.addEventListener('input', (e) => {
$app.style.setProperty('--radius', e.target.value + 'px');
});
Also see: Tab Triggers