What's the best way to style 45 bevel corners?

Tried a few ways, but they mostly seem like hacks. Solution should achieve the following results: - consistent border width, even along angled corner - require only one div/class (no inner+outer containers) - use either the outline or border attribute - allow for css transitions or animations or keyframes etc. some solutions use the background-image attribute, which restricts basic animations. - fixed or responsive corner dimensions
No description
16 Replies
capt_uhu
capt_uhu2d ago
unfortunately the mythical answer we all seek for this just doesn't exist yet. Right now it's spec-ed as corner-shape but is not ready to be implemented in browsers: https://drafts.csswg.org/css-borders-4/#corner-shaping
13eck
13eck2d ago
This sounds like a homework assignment. And a dumb one at that. They want you to ::checks notes:: do the impossible…
ἔρως
ἔρως2d ago
you can make this with an svg image as the background, and then use a clip-path to keep things inside however, clipping cuts the content off, and doesnt re-layout the stuff inside
MarkBoots
MarkBoots2d ago
well, you could also use shape-outside to prevent the content being clipped. I wouldn't say it is impossible, But yea, this is a real hassle, not really something easy to do with the given constraints
ἔρως
ἔρως2d ago
and the hardest requirement is to only use a single element for this
Jochem
Jochem2d ago
hardest and most nonsense why the heck would you limit yourself to BS like that, other than as an exercise, in which case "best" doesn't matter?
Kevin Powell
Kevin Powell2d ago
Kevin
CodePen
Responsive/Adaptive cut corners
A cut-corner border effect using pseudo-elements. Updating the custom properties lets you change the border (gradient or solid color), background color...
Kevin Powell
Kevin Powell2d ago
I did two edges here, but you could take the same approach for one.
13eck
13eck2d ago
Dangit, Kevin! Why you gotta show us up like that!? But, but Kevin. There's JavaScript in that pen! 😱
Kevin Powell
Kevin Powell2d ago
i didn't use an outline or border though... that's just so you can adapt it with the sliders 😛
13eck
13eck2d ago
The King has failed the test lol
Kevin Powell
Kevin Powell2d ago
If it is an assignment of some sort, I'd really like to know what the solution is, using a border or outline 😅 unless it's a border-image, but then I can't imagine the corner dimensions would be adaptable/resposive
ἔρως
ἔρως2d ago
i remember that video but what happens if the content touches the sides?
Kevin Powell
Kevin Powell2d ago
Should be fine, the "border" is "inside" the element. Or do you mean the content inside the element, like if the text is longer? if that's what you mean, it's using padding, so it gets bigger/smaller with the text
ἔρως
ἔρως2d ago
yeah, but if you dont have the padding, will the text show on top of the pseudo-elements? will it be cut off? because the assignment seems to be to layout text and stuff around the diagonal, instead of going missing or something maybe the thingy to shape text around a floating image will work for that?
i_lost_to_loba_kreygasm
can you explain what's going on? or how did you get the border effect ? or if anyone else can explain , that would be appreciated too 🙂

Did you find this page helpful?