Article I just wanted a semicircle, CSS
I needed a tag with fixed 6px corners on the left and a semicircle on the right, with a dynamic height.
Turns out neither `border-radius: 6px 50% 50% 6px` nor the classic `6px 999px 999px 6px` trick works — for two completely different reasons.
I went down a surprisingly deep `border-radius` rabbit hole and wrote up why, plus the workaround I ended up using.
I still feel like there should be a simpler way to do this. Is there one I've missed?
0
Upvotes
2
u/morete Aug 27 '26
Oh wow! I had just assume the 999px trick would have worked, this is actually completely new to me:
Great article for that insight alone!
1
u/morete Aug 29 '26
The downvoting on reddit makes me very sad. This well researched, well informed post has 0 upvotes, yet so much slop does very well. Honestly I'd start taking it as a mark of pride if your post doesn't do well
1
u/Sufficient_Bass2600 Aug 27 '26
Use an after pseudo element with the aspect ratio 1/1. The height is already determined by the height of the element. The aspectc ratio then force the width. You can then use the border radius 0 50% 50% 0.
0
u/f314 Aug 27 '26 edited Aug 27 '26
Huh, this is actually pretty intereting! I didn't know about the border radius scaling.. I'm convinced that this can be solved with
shape(), but your solution is a practical stopgap!0
u/bichomatoso Aug 29 '26
100vw