123

Pen Settings

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URL's added here will be added as <link>s in order, and before the CSS in the editor. If you link to another Pen, it will include the CSS from that Pen. If the preprocessor matches, it will attempt to combine them before processing.

+ add another resource

You're using npm packages, so we've auto-selected Babel for you here, which we require to process imports and make it all work. If you need to use a different JavaScript preprocessor, remove the packages in the npm tab.

Add External Scripts/Pens

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.

+ add another resource

Use npm Packages

We can make npm packages available for you to use in your JavaScript. We use webpack to prepare them and make them available to import. We'll also process your JavaScript with Babel.

⚠️ This feature can only be used by logged in users.

Code Indentation

     

Save Automatically?

If active, Pens will autosave every 30 seconds after being saved once.

Auto-Updating Preview

If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.

HTML Settings

Here you can Sed posuere consectetur est at lobortis. Donec ullamcorper nulla non metus auctor fringilla. Maecenas sed diam eget risus varius blandit sit amet non magna. Donec id elit non mi porta gravida at eget metus. Praesent commodo cursus magna, vel scelerisque nisl consectetur et.

            
              <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>

            
          
!
            
              // ------------------------------
// 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. To save a few lines of code, reuse the same pseudo-element styles and just flip the right 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 }), transparent calc(100% - #{$triangle-width / 2 * 1px }));
	}

	&::before {
		left: 0;
	}

	&::after {
		left: 50%;
		transform: scaleX(-1); // 6. Flip pseudo-element
	}
}



// ------------------------------
// Decorations
// ------------------------------

body {
	background-color: lightgray;
}

h1 {
	text-align: center;
}

h2 {
	margin-top: 0;
}

div {
	width: 300px;
	margin: auto;
	padding: 1rem;
}

            
          
!
999px
🕑 One or more of the npm packages you are using needs to be built. You're the first person to ever need it! We're building it right now and your preview will start updating again when it's ready.

Console