Skip to content

Latest commit

 

History

History
69 lines (55 loc) · 2.23 KB

shape-separator.md

File metadata and controls

69 lines (55 loc) · 2.23 KB

Shape separator

Uses an SVG shape to separate two different blocks to create more a interesting visual appearance compared to standard horizontal separation.

HTML

<div class="shape-separator"></div>

CSS

.shape-separator {
  position: relative;
  height: 48px;
  background: #333;
}
.shape-separator::after {
  content: '';
  background-image: url(data:image/svg+xml;base64,PHN2ZyB2aWV3Qm94PSIwIDAgMjQgMjQiIHhtbG5zPSJodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2ZyIgZmlsbC1ydWxlPSJldmVub2RkIiBjbGlwLXJ1bGU9ImV2ZW5vZGQiIHN0cm9rZS1saW5lam9pbj0icm91bmQiIHN0cm9rZS1taXRlcmxpbWl0PSIxLjQxNCI+PHBhdGggZD0iTTEyIDEybDEyIDEySDBsMTItMTJ6IiBmaWxsPSIjZmZmIi8+PC9zdmc+);
  position: absolute;
  width: 100%;
  height: 24px;
  bottom: 0;
}

Demo

<style> .snippet-demo__shape-separator { position: relative; height: 48px; margin: -0.75rem -1.25rem; } .snippet-demo__shape-separator::after { content: ''; background-image: url(data:image/svg+xml;base64,PHN2ZyB2aWV3Qm94PSIwIDAgMjQgMjQiIHhtbG5zPSJodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2ZyIgZmlsbC1ydWxlPSJldmVub2RkIiBjbGlwLXJ1bGU9ImV2ZW5vZGQiIHN0cm9rZS1saW5lam9pbj0icm91bmQiIHN0cm9rZS1taXRlcmxpbWl0PSIxLjQxNCI+PHBhdGggZD0iTTEyIDEybDEyIDEySDBsMTItMTJ6IiBmaWxsPSIjZmZmIi8+PC9zdmc+); position: absolute; width: 100%; height: 24px; bottom: 0; } </style>

Explanation

  1. position: relative on the element establishes a Cartesian positioning context for pseudo elements.
  2. ::after defines a pseudo element.
  3. background-image: url(...) adds the SVG shape (a 24x24 triangle in base64 format) as the background image of the pseudo element, which repeats by default. It must be the same color as the block that is being separated.
  4. position: absolute takes the pseudo element out of the flow of the document and positions it in relation to the parent.
  5. width: 100% ensures the element stretches the entire width of its parent.
  6. height: 24px is the same height as the shape.
  7. bottom: 0 positions the pseudo element at the bottom of the parent.

Browser support

✅ No caveats.