In the past, the only option to achieve this was using SVG images. Today, we can have multiple solutions and I’ll try my best to show you all possibilities.
Personally, I think that for simple sloped edges, we can use border property in CSS as the best solution, but for more complex shapes, we should still stick with SVG.
Since the time of this writing, you’ve probably come across many web applications that already have some creative design solutions for their sections. Angled/Sloped edges are nothing new, but we should investigate this further and try all possible solutions for this nifty feature…
I wrote a couple of CodePen examples. They all look identical in the end, but there are some pros and cons as always, to each one. I’ll write about cons, but you decide about pros…
CON: Depends upon viewport unit
Sloped Edge — Solution using “border” property in CSS
CON: Horizontal resize breaks it
Sloped Edge — Solution using “transform: skewY()” property in CSS
CONS:- Vertical resize breaks it- Bad browser coverage
Sloped Edge — Solution using “clip-path: polygon()” property in CSS
CONS: - It makes your HTML messy- Duplication of SVG images for various sections- Creating new SVG images for different angles
Sloped Edge — Solution using “SVG” images in HTML
Using one of the solutions from above, but developed to be flexible for use across the entire application.
that embeds “SVG” in “background-image” property in CSS
If you like this approach, check his Angled Edges repository on GitHub for more information. This mixin supports a couple of different positions and you might want to check official example as well.
josephfusco/angled-edges_angled-edges - 📐 Quickly create angled section edges using only Sass_github.com
Personal Review:This Mixin has unclear documentation in README file and lacks the source-maps in a demo. It shows CSS instead of SCSS, so people might have some trouble implementing this. Although, I just had issues figuring how to use
_$_position
and$hypotenuse
arguments. By playing around with it, I figured out how to implement it to match other examples. It has some cons too, but I’ll let you try to figure them out in comments?
Sloped Edge — Solution using “Angled Edges” Sass Mixin, developed by Joseph Fusco
using “border” property in CSS
My personal preference for Sloped Edges is by using “border” property. If you’re like me and prefer this approach, I highly suggest you to check out my Sloped Edge repository on GitHub for more information. There are a couple of possibilities with this mixin, as it supports a few different options. Not only that it works for right and left angles, it also has in and out option and it is not made only for vertical layouts, but horizontal layouts as well.
dvlden/sloped-edge_sloped-edge - Sass mixin that helps you build sloped section edges with a consistent angle._github.com
Make sure to check out both layout examples with all possible use cases:
Sloped Edge — Solution using “Sloped Edge” Sass Mixin, developed by Nenad Novaković
You might also find a solution with CSS property transform: rotate()
elsewhere, but it requires an “overflow: hidden” property to its parent. I find that to be very bad and should not be even considered as a solution.
If you enjoyed this and learned something new, please share some love.To do so, tap the clap icon 👏 or hold it for more claps! 👏👏👏
Much appreciated. You’re the best!