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.
<h1>Triangle Cutout</h1>
<br>
<div class="triangle-cutout">
<h2>Section Heading</h2>
<p>Lorem ipsum dolor sit amet consectetur adipisicing elit. Placeat blanditiis repellat, sed provident obcaecati explicabo rerum minus eum suscipit beatae laboriosam necessitatibus nihil! Ipsum quasi, aliquid nesciunt quis quod aliquam?</p>
</div>
<section>
<h2>Browser Support <small>(as of 2020-02-21)</small></h2>
<dl>
<dt>IE</dt><dd>✅ 9+</dd>
<dt>Edge</dt><dd>✅</dd>
<dt>Firefox</dt><dd>✅ 4+</dd>
<dt>Chrome</dt><dd>✅ 19+</dd>
<dt>Safari</dt><dd>✅ 6+</dd>
<dt>Opera</dt><dd>✅ 15+</dd>
<dt>iOS Safari</dt><dd>✅ 6.1+</dd>
<dt>Opera Mini</dt><dd>⚠️ Fallback</dd>
<dt>Android Browser</dt><dd>✅ 4.4+</dd>
<dt>Chrome for Android</dt><dd>✅</dd>
</dl>
<h3>Internet Explorer</h3>
<img src="https://s3-us-west-2.amazonaws.com/s.cdpn.io/146527/2020-02-21-triangle-cutout-in-internet-explorer-11.png" alt="">
</section>
// ------------------------------
// Helpers
// ------------------------------
@function str-replace($string, $search, $replace: '') {
$string: inspect($string);
$index: str-index($string, $search);
@return if($index,
str-slice($string, 1, $index - 1) + $replace +
str-replace(str-slice($string, $index +
str-length($search)), $search, $replace),
$string);
}
// ------------------------------
// Triangle Cutout
// ------------------------------
/*
1. Use unitless values for the triangle's width/height so they can be used in an SVG without doing extra work to strip the "px" unit (instead, add `px` where needed with `$value * 1px`).
2. Use `filter: drop-shadow` on the parent so the shadow seamlessly applies to the whole element.
3. Use an SVG background-image to create the triangle "cutout" effect.
4. To keep the transparent area behind the SVG, use a linear-gradient to fill in the remaining space.
5. (Optional) Depending on the size of your triangle, some browsers at some screen sizes will approximate the position of the gradient, adding an empty 1px border between the triangle and the gradient fill. To get around this, subtract a half pixel from the gradient's position so its edges always overlap.
6. Reverse the triangle on the rigth side.
*/
.triangle-cutout {
// 1. Unitless values
$triangle-width: 60; // px
$triangle-height: 30; // px
$background-color: #fff;
position: relative;
margin-top: $triangle-height * 1px;
background-color: $background-color;
filter: drop-shadow(0 0 20px rgba(0, 0, 0, 0.2)); // 2. drop-shadow
&::before,
&::after {
content: '';
position: absolute;
bottom: 100%;
width: 50%;
height: $triangle-height * 1px;
background:
// 3. SVG background-image
url("data:image/svg+xml,%3Csvg width='#{$triangle-width / 2}' height='#{$triangle-height}' viewBox='0 0 #{$triangle-width / 2} #{$triangle-height}' xmlns='http://www.w3.org/2000/svg'%3E%3Cpolygon fill='#{str-replace($background-color, '#', '%23')}' points='0 0 0 #{$triangle-height} #{$triangle-width / 2} #{$triangle-height}' /%3E%3C/svg%3E") right top / ($triangle-width / 2 * 1px) ($triangle-height * 1px) no-repeat,
// 4. linear-gradient background-image
// 5. (Optional) Subtract a half-pixel for aliasing
linear-gradient(to right, $background-color calc(100% - #{$triangle-width / 2 * 1px }), rgba($background-color, 0) calc(100% - #{$triangle-width / 2 * 1px }));
}
&::before {
left: 0;
}
&::after {
left: 50%;
background:
// 6. Reverse triangle on the right side
url("data:image/svg+xml,%3Csvg width='#{$triangle-width / 2}' height='#{$triangle-height}' viewBox='0 0 #{$triangle-width / 2} #{$triangle-height}' xmlns='http://www.w3.org/2000/svg'%3E%3Cpolygon fill='#{str-replace($background-color, '#', '%23')}' points='0 #{$triangle-height} #{$triangle-width / 2} #{$triangle-height} #{$triangle-width / 2} 0' /%3E%3C/svg%3E") left top / ($triangle-width / 2 * 1px) ($triangle-height * 1px) no-repeat,
linear-gradient(to left, $background-color calc(100% - #{$triangle-width / 2 * 1px }), rgba($background-color, 0) calc(100% - #{$triangle-width / 2 * 1px }));
// (Optional) If you don't need to support IE11, you can save a few lines of code by replacing `background` with this simple `transform`.
// transform: scaleX(-1);
}
}
// ------------------------------
// Decorations
// ------------------------------
body {
background-color: lightgray;
}
h1 {
text-align: center;
}
h2 {
margin-top: 0;
}
h3 {
margin-top: 2rem;
}
div {
width: 300px;
margin: auto;
padding: 1rem;
}
section {
margin: 6rem auto;
max-width: 42rem;
padding: 1rem;
background: white;
line-height: 1.4;
tab-size: 4;
}
img {
max-width: 100%;
}
// --------------------------------
// Definition List w/ Leading Lines
// https://codepen.io/tannerhodges/pen/YrPMgv
// --------------------------------
dl {
display: grid;
grid-template-columns: auto 1fr;
grid-column-gap: 1em;
grid-row-gap: 0.5em;
margin: 1em;
line-height: 1.3;
}
dt {
position: relative;
grid-column: 1;
font-weight: bold;
overflow: hidden;
}
dd {
grid-column: 2;
margin-left: 0;
}
dt::after {
position: absolute;
top: 0.6em;
width: 100%;
margin-left: 0.75em;
border-bottom: 1px dotted #ccc;
content: '';
}
Also see: Tab Triggers