I'm looking to "cut" the top left corner of a div, like if you had folded the corner of a page down.
I'd like to do it in pure CSS, are there any methods?
I'm looking to "cut" the top left corner of a div, like if you had folded the corner of a page down.
I'd like to do it in pure CSS, are there any methods?
If you need a transparent cut out edge, you can use a rotated pseudo element as a background for the
div
and position it to cut out the desired corner:Note that this solution uses transforms and you need to add the required vendor prefixes. For more info see canIuse.
To cut the bottom right edge, you can change the top, transform and transform-origin properties of the pseudo element to:
We had the problem of different background colors for our cutted elements. And we only wanted upper right und bottom left corner.
by small modification of Joshep's code...You can use this code which seems like right corner folded down as per your requirement.
You could use
linear-gradient
. Let's say the parentdiv
had a background image, and you needed adiv
to sit on top of that with a gray background and a dog-eared left corner. You could do something like this:See it on CodePen
Further reading:
Here is another approach using CSS
transform: skew(45deg)
to produce the cut corner effect. The shape itself involves three elements (1 real and 2 pseudo-elements) as follows:div
element hasoverflow: hidden
and produces the left border.:before
pseudo-element which is 20% the height of the parent container and has a skew transform applied to it. This element prodcues the border on the top and cut (slanted) border on the right side.:after
pseudo-element which is 80% the height of the parent (basically, remaining height) and produces the bottom border, the remaining portion of the right border.The output produced is responsive, produces a transparent cut at the top and supports transparent backgrounds.
The below is another method to produce the cut corner effect by using
linear-gradient
background images. A combination of 3 gradient images (given below) is used:The output produced is responsive, produces transparent cut and doesn't require any extra elements (real or pseudo). The drawback is that this approach would work only when the background (fill) is a solid color and it is very difficult to produce borders (but still possible as seen in the snippet).
CSS Clip-Path
Using a clip-path is a new, up and coming alternative. Its starting to get supported more and more and is now becoming well documented. Since it uses SVG to create the shape, it is responsive straight out of the box.
CSS Transform
I have an alternative to web-tiki's transform answer.