intersecting borders

How can I prevent div borders from being accumlated on top of each other like here https://codepen.io/sos909/pen/GRLPyzy The border between the 2 divs is wider than all the other sides, how can I make it consistent
SOS909
CodePen
GRLPyzy
...
22 Replies
ἔρως
ἔρως8mo ago
try margin: -1px on the 2nd div
sos
sosOP8mo ago
That works but I have alot of divs so I want something that works without having to manually add margin for specific divs I tried using outline instead of borders and it works but when I added background-color the width of the outline decreases for some reason
sos
sosOP8mo ago
This is using outline
No description
sos
sosOP8mo ago
see how the top side of the div is thinner than the bottom
outline: 2px solid black;
background-color: orange;
outline: 2px solid black;
background-color: orange;
These are the only styles being appiled to that element
ἔρως
ἔρως8mo ago
the outline is "outside" the size of the element what you can do is skip the border border-collapse seems to only work on tables
sos
sosOP8mo ago
wdym by skip the border
ἔρως
ἔρως8mo ago
border-top: none
clevermissfox
clevermissfox8mo ago
Box-shadow is another one you could try, like outline it doesn’t take up space.
ἔρως
ἔρως8mo ago
or border-top-width: 0 the downside of those is that it doesn't take up space
Tok124 (CSS Nerd)
You can do this
No description
Tok124 (CSS Nerd)
Or this
No description
ἔρως
ἔρως8mo ago
the top one is easier to read instead of .box + .box, you can use .box + * it's slightly different, but for this example it does the same oh, another idea: margins collapse, so, set a background to the parent element and set a different background for the .box with a margin
sos
sosOP8mo ago
I tried adding z-index: -1 to all my colored divs and now its working It was something with the order of displaying I think using outlines btw
ἔρως
ἔρως8mo ago
DO NOT DO THAT! that is an horrible idea
sos
sosOP8mo ago
what why
ἔρως
ἔρως8mo ago
NEVER EVER EVER GO NEGATIVE unless you know what you're doing it introduces tons of issues mostly: anything and everything will get in front of it, the background won't work properly and other weird stuff will happen
sos
sosOP8mo ago
what if I set z-index: 100 to all my uncolored divs
ἔρως
ἔρως8mo ago
that's bad it will get in front of other stuff you will then be fighting to keep menus and other things on top in the end, you will be setting z-index: 99999999999999999999 to everything you want always on top which is also very bad
MarkBoots
MarkBoots8mo ago
if possible for your use case. i would wrap it in a separate div. and give that wrapper an outline with the same width
No description
ἔρως
ἔρως8mo ago
that works, but limits the outline usage
MarkBoots
MarkBoots8mo ago
or shadow or border
ἔρως
ἔρως8mo ago
however, you should never have focus on a div, so, it's fine
Want results from more Discord servers?
Add your server