w3c / csswg-drafts

CSS Working Group Editor Drafts
https://drafts.csswg.org/
Other
4.49k stars 662 forks source link

[css-borders] Multi-layer support for `border-image` #8802

Open LemmaEOF opened 1 year ago

LemmaEOF commented 1 year ago

Spec: https://w3c.github.io/csswg-drafts/css-backgrounds/#border-images

The current state of border-image is...less than stellar. There are two main problems I've run into:

  1. Unlike background-image, border image sources cannot be layered. 2. Border images are fully unaffected by border-style and border-radius.

The former is a simple parity issue - the value of border-image-source could be converted from none | <image> to <bg-image># without breaking existing CSS, and the other border-image properties could be made to support groups as well.

While the latter makes a lot of sense for using a sliced image, this becomes an issue if you want to use a gradient as a border - as <gradient> is a subtype of <image>, this results in gradient borders being unable to use the features you'd use with a solid-colored or hidden border. While there are workarounds, they're not pretty - take for example this post from blep on cohost.

I'm not quite sure of an optimal solution for this, as changing it would inherently change the visual presentation of any websites that use the current behavior. However, I feel it's still important to consider, as design trends like neumorphism are starting to bring back gradients in ways where having a gradient border with a radius would be desirable.

I'm new to spec proposals, so please don't hesitate to let me know if I've missed anything! Thank you for your time!

EDIT: second point is generally resolved, but I still feel like multi-layer border images would be worth proposing.

Loirooriol commented 1 year ago

Regarding border-radius, I don't think it makes sense for 2D images. It can make sense for <image-1D> though. Rather than border-image, this seems better suited for border-color, which already accepts stripes() in level 4. I guess you want something like stripes() but mixing the colors smoothly instead of in discrete stripes.

LemmaEOF commented 1 year ago

The issue with something like stripes() is that stripes() on a border-color are always inside-out and can't pick their own direction - something like the outer border the above-linked post would still be impossible, as it specifies a diagonal gradient: Capto_Capture 2023-05-05_04-12-53_PM

Loirooriol commented 1 year ago

OK sure, I thought you wanted another effect, that's not suitable for <image-1D>. But consider using backgrounds:

background: linear-gradient(to bottom right, #3c3c3c, #292929) padding-box,
            linear-gradient(to bottom right, #ffffff, #ffff00, #ff0000, #ff00ff) border-box;

Full code ```html
Lorem ipsum
```
LemmaEOF commented 1 year ago

Oh, huh - that actually works really cleanly! I still personally feel like it could be wrapped into borders themselves, but I understand why it wouldn't quite fit. I'll still leave this issue up for the sake of multi-layer border images, though - that feels like a generally good idea overall.

jsnkuhn commented 1 year ago

The issue with the 2 layers of gradients to solve this is that it makes using an actual background image a bit more difficult than is ideal. I also don't see a way to use a transparent background with this?

For the moment an SVG border-image that includes the gradient filled stroke is probably the best way to go unless you need the gradient to animate on hover i guess.

Having a straightforward CSS solution for this would still be ideal. https://github.com/w3c/csswg-drafts/issues/7550

Also here is a previous issue regarding manipulating the border-image-source before slicing: https://github.com/w3c/csswg-drafts/issues/7777