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
CON: Horizontal resize breaks it
- Vertical resize breaks it
- Bad browser coverage
- It makes your HTML messy
- Duplication of SVG images for various sections
- Creating new SVG images for different angles
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.
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
$hypotenusearguments. 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?
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.
Make sure to check out both layout examples with all possible use cases:
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!