:root {
--width: 100%;
--height: 100px;
--top-color: #f44336;
--bottom-color: #2196F3;
}
.separator {
width: var(--width);
height: var(--height);
background-image: linear-gradient(to bottom right, var(--top-color), var(--top-color) 50%, var(--bottom-color) 50%, var(--bottom-color));
}
.separator.reverse {
background-image: linear-gradient(to bottom left, var(--top-color), var(--top-color) 50%, var(--bottom-color) 50%, var(--bottom-color));
}
.separator.vertical.reverse {
background-image: linear-gradient(to top right, var(--top-color), var(--top-color) 50%, var(--bottom-color) 50%, var(--bottom-color));
}
Notes:
- 👍 The angle is controlled by the element height value
- 👎 Jagged / blurry edges on some rendering engines
- tweak the percentage a little to get a better rounding algorithm.
- 👎 Further control is limited
- e.g. creating a shadow effect using
box-shadow
- e.g. creating a shadow effect using
Can be used with the ::before
and ::after
pseudo-elements to generate HTML content for the separator without directly modifying your DOM.
section {
...
}
section::after {
width: 100%;
height: 50px;
background-image: linear-gradient(to bottom right, yellow, yellow 50%, black 50%, black);
}
Supported in all major browsers, with the exception of
Opera Mini
.
View Demo, Play on CodePen, or inspect the source files.