DEV Community

Cover image for I have made 100+ CSS-only Ribbon Shapes | The Perfect Collection πŸŽ€

I have made 100+ CSS-only Ribbon Shapes | The Perfect Collection πŸŽ€

Temani Afif on November 13, 2023

It's time for another collection! After the loaders, the hover effects, and the background patterns, let's make some Ribbon Shapes! πŸ‘‰...
Collapse
Β 
grahamthedev profile image
GrahamTheDev β€’ β€’ Edited

Love these bud! πŸ”₯πŸ’—

Was really impressed when I saw the multi-line one on Twitter (X)...they are really smart! πŸ’ͺ🏼

For anyone wondering how to fix the broken ones (as Firefox doesn't support "lh" units in older / still current versions) you can manually set that property or use CSS vars to set a font size and a line height property that you can then use.

I am sure Temani has an even simpler solve, but this worked for me:

.ribbon {
    --ribbon-line-height: 1.8; /* added line height var */
  font-size: 24px;
  font-weight: bold;
  color: #fff;
}
.ribbon {
  --f: .5em; /* control the folded part */

  position: absolute;
  top: 0;
  right: 0;
  line-height: var(--ribbon-line-height); /* changed */
  padding-inline: calc(1em * var(--ribbon-line-height)); /* changed */
 [...continued]
}
Enter fullscreen mode Exit fullscreen mode
Collapse
Β 
afif profile image
Temani Afif β€’

Actually, an easy fix is to map 1lh to 1.8em (if for example you are setting line-height: 1.8). In the codepen (like the multi-line ones) I am including the fallback but I am not doing this for the collection because the support will be good starting from next week and I am hiding half the ribbons on Firefox.

A lazy move but it would be a lot of effort to add all the fallbacks that will be useful for only a short period of time.

Collapse
Β 
alvaromontoro profile image
Alvaro Montoro β€’

Great article! πŸ‘πŸ‘

Collapse
Β 
afif profile image
Temani Afif β€’

A lot of shapes are for sure broken on Safari so if you have the time to identify the bug it would be good if you can report it.

A few shapes relies on the "lh" unit that will land soon on Firefox so you won't see the full collection on Firefox before the end of the month.

Collapse
Β 
citronbrick profile image
CitronBrick β€’

Does it work on iOS Safari ?

Collapse
Β 
mazonthemoon profile image
Mary Ronan β€’

❀❀❀

Collapse
Β 
jagadeeshgade008 profile image
jagadeeshgade008 β€’

awesome!!!

Collapse
Β 
kurealnum profile image
Oscar β€’

These are really cool, great job!

Collapse
Β 
1link profile image
1Link.Fun β€’

Very nice~ thanks!

Collapse
Β 
afif profile image
Temani Afif β€’

It's on Twitter (X) πŸ‘‡

Collapse
Β 
jonrandy profile image
Jon Randy πŸŽ–οΈ β€’ β€’ Edited

#5 and #6 seem to be broken (at least in Firefox). Easily fixable

Collapse
Β 
afif profile image
Temani Afif β€’

I am hiding the 5 and 6 on Firefox because they rely on the lh unit which is not yet supported. You should not be able to see them using Firefox unless you copied the code using chrome and you tried to see them using Firefox.

Collapse
Β 
jonrandy profile image
Jon Randy πŸŽ–οΈ β€’

Perfectly visible on Firefox - I just went to the link.

Change the conical gradient value to 50.1% and they're fixed. Not sure if that breaks Chrome or not though

Thread Thread
Β 
afif profile image
Temani Afif β€’

any value bigger than 50% should do the job and I suppose you are using Firefox nighty because the actual version of Firefox (119) doesn't support lh and the support will start at 120 (end of this month) so actually I don't care about half of the ribbon on Firefox until the release of 120. I will have a lot of bug to fix related to lh anyway.

Thread Thread
Β 
jonrandy profile image
Jon Randy πŸŽ–οΈ β€’

Yup, I'm using Nightly (121)