Custom border - possible?

Hi everyone! I need to create the double border border in the attached image, and have it dynamically fit the content inside (be it image or text). what would be the best approach?
No description
25 Replies
ἔρως
ἔρως2mo ago
currently, you can't do it, because of this: https://discord.com/channels/436251713830125568/1364233248913490004/1384167980073619561 lets just say that it is new enough to the point that there's not even an mdn page you can probably fake it, but, it's way too much squeezing for no juice at all
Solin
SolinOP2mo ago
that's what i thought too. and SVGs can't somehow allow content inside and adapt to them,can they 😛
ἔρως
ἔρως2mo ago
you can shove anything you want inside a <foreignObject> but it is inside an svg you can make a background with it, but ...
Solin
SolinOP2mo ago
hmmm i don't mind this. does it accept images and text?
ἔρως
ἔρως2mo ago
you can use the <text> and <image> elements is this for a personal project or something public?
Solin
SolinOP2mo ago
public
ἔρως
ἔρως2mo ago
don't use an svg seriously, just make the borders simpler you can use the border-style property for double borders: https://developer.mozilla.org/en-US/docs/Web/CSS/border-style
Solin
SolinOP2mo ago
neat, thanks! i'll check that out.
ἔρως
ἔρως2mo ago
or you just use multiple (pseudo)-elements, if you need more control that design is very overcomplicated
Solin
SolinOP2mo ago
on a different note, i've seen some people use dropshadows to replicate borders, but in a way where they don't really add to what a regular border does. any reason they might do that?
ἔρως
ἔρως2mo ago
i would do that as a way to add an outline instead, without messing with the outline property
Solin
SolinOP2mo ago
mmm to what benefit?
ἔρως
ἔρως2mo ago
https://developer.mozilla.org/en-US/docs/Web/CSS/box-shadow <-- follows border radius, as far as i can see https://developer.mozilla.org/en-US/docs/Web/CSS/outline <-- outline's implementations had issues with border radius for a very long time
Solin
SolinOP2mo ago
Thanks!
capt_uhu
capt_uhu2mo ago
so here's an attempt. Seems like a dumpster fire waiting to happen though. Needs more vars to be maintainable at all. Stuff like this is why we need corner-shape : https://codepen.io/jsnkuhn/pen/PwqLGvY
ἔρως
ἔρως2mo ago
that is some nice fakery
No description
ἔρως
ἔρως2mo ago
it has some issues and needs some tweaking, but it is really really good
vince
vince2mo ago
Why not use clip path & a pseudo element?
ἔρως
ἔρως2mo ago
No description
ἔρως
ἔρως2mo ago
that's what he did
vince
vince2mo ago
Ohh sorry
capt_uhu
capt_uhu2mo ago
there are a bunch of different ways to do this with clip path and pseudo elements. The reason I chose this one is it also incorporates the border property so it would be easier to run an at supports for corner-shape. I added that to the pen.
Solin
SolinOP2mo ago
if i ignore the double border and just try to add one border with the slants etc, is that doable easily?
ἔρως
ἔρως2mo ago
the slants are the harder part
capt_uhu
capt_uhu2mo ago
you wouldn't need all the pseudo elements. the background, clip-path and border could just go right on the element itself. But it's still going to be fiddly at best until corner-shape.

Did you find this page helpful?