diagonal borders
Well, I tried
But as you can see, on the top one it works, on the bottom one you've get the 1px "spacing".
I mean I could try to overshoot the top one like I did the bottom on with "-1px" - but this results also in that the diagonal ends to "soon" on the right (see the bottom) - unless I "fix this better". But this looks to be a bit dirty to me.
So any idea how to fix it or different approach (and it's still antialiased)? I'm not sure with SVGs if you could style them with CSS (fill color and maybe optional height).
Maybe working with :before / after und before goes into negative values? The elements come within a loop - so they maybe overlap then - and I need to link the anchors (ids) or their parent

41 Replies
how about you make a triangle with ::before and ::after?
that has been possible to do since ever, and you can easily find the code online
I dont know if clip-patch also works there
it's one google search away
it does, but dont overcomplicate
also, the support for css triangles is much better
hm ok. I wont be just triangles, but also other shapes
So I think I need to go that polygon or svg way
yeah, but for the triangle, just dont overcomplicate
maybe I should change the topic to "polygonic borders"
Problem is that 1 blank line which is maybe because of rounding problems
I see v-html is this vue?
yes
Aha
nuxt3
But for you problem maybe try border-image and have a svg with your desired shape?
can you set the background color of svgs via css?
For background color you can just use regular css.
not sure about that - just did "pure svg" editing in html so far
so the fill color
Like only do the outlining using the svg. You can always use the full shape and position the text absolute on top of it. But that's gonna get tricky to be responsive I think.
If you add the svg inline you can style the svg,path etc tags.
I think border-image is the more elegant solution but a little trickier to get right. And the position absolute one more bruud forced kinda.
I mean border-image is for the border only.
The background is handled seperatly.
hmm... well all the stuff will come from a cms where people can say "this border style at this color"
much stuff to do then
You can do the border-image inline inside the html and allow people to upload svg for border.
well they just get a choce of like 4-5 border styles
For the absolute solution you just gotta use the solution to render the svg as svg from the CMS.
You got a dropdown element?
Yes
element style gets submitted and added as css classes
Name them appropiate, and then use the dropdown so the client can decide what shape they want. If you use BEM notation for css you can do the border-image svg per modifier.
What CMS are you using?
I use BEM - a bit
self written one
Doesnt have to be BEM but you can do similar.
BEM is self written tho.
Like
c-section c-section--heart
would create the section with a heart border. The dropdown could have a option 'heart' for the client to chose.the cms is a self written one. Well I use BEM - mainly just for modifiers - elements I never know and are a bit unnecessary when you do the style scoped in the components
You replace heart with a variable that comes from the CMS.
You can do that with vue right? Directly manipulate the css using js variables?
c-section c-section--${variable}
. Something like this.:D
That's not how you use BEM
so for elements I never know where to cut the element
You use modifiers to slightly alternate the styles. Let's say you have a badge per categorie this badge has a different color then you can do
c-badge c-badge--${category}
but with scoped styling you barely need to use bem
Still if you use it you should use it correctly.
BEM is a solution for specifity problems. If you use BEM properly you almost never run into a spicifity issue.
Oh no
You don't have to repeat the inner everytime.
damn double _ 😄
The way you do it
well, however - I usually go with component styling and just put common stuff like colors, fonts, standard paddings in a global css
and with component styling you don't really need bem
An element is always part of a block, not another element. This means that element names can't define a hierarchy such as blockelem1elem2.Nvm
however - that clip path - sometimes rounding a pixel false (at least I think it does) - that on topelement in my screenshot it works, bottom it gets suddenly a white line. so try svgs as they're more accurate? And I can set the fill-color by css classses? .top--blue, top--grey, ...
background isn't always white - so inverse the shape wouldn't work as well I think
i've run into that "one pixel off" (sometimes it seems like it might be less than one pixel) positioning issue a few times. Seems to mostly happen for me in just Firefox. In my experience it doesn't really matter what I use to add the shape on (another element or pseudo or svg etc) it's always there.
So what i tend to do instead is cut the shape out of an over sized element. In this case add padding to top and bottom then then clip-path the whole element. https://codepen.io/jsnkuhn/pen/RNWowdw
@jsnkuhn thx! I tried it with some "-1px stuff" to get rid off the 1px rounding error.