Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
LemmaEOF opened this issue May 5, 2023 · 5 comments
Open

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

LemmaEOF opened this issue May 5, 2023 · 5 comments

Comments

@LemmaEOF
Copy link

LemmaEOF commented May 5, 2023

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
Copy link
Contributor

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
Copy link
Author

LemmaEOF commented May 5, 2023

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
Copy link
Contributor

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
<!DOCTYPE html>
<style>
:root {
  background: #555555;
}
div {
  background: linear-gradient(to bottom right, #3c3c3c, #292929) padding-box,
              linear-gradient(to bottom right, #ffffff, #ffff00, #ff0000, #ff00ff) border-box;
  border: 1px solid transparent;
  border-radius: 1em;
  height: 100px;
  width: 200px;
  padding: 1em;
  color: #ffffff;
}
</style>
<div>Lorem ipsum</div>

@LemmaEOF
Copy link
Author

LemmaEOF commented May 5, 2023

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.

@LemmaEOF LemmaEOF changed the title [css-background] Multi-layer and border style/radius support for border-image [css-background] Multi-layer support for border-image May 5, 2023
@jsnkuhn
Copy link

jsnkuhn commented May 6, 2023

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.
#7550

Also here is a previous issue regarding manipulating the border-image-source before slicing:
#7777

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants