:focus outline being overlapped.

Hey, so my focus outline on this button is being overlapped by the div as you can see in the image. I can't seem to re-create this problem in codepen so i understand if no one can give any proper advice, i'm more trying to see if anyone has had this happen to them or knows what could cause it. My structure is like so:
<div>
<div>
<button>button</button>
</div>
<div class="container">
...
</div>
</div>
<div>
<div>
<button>button</button>
</div>
<div class="container">
...
</div>
</div>
.container has position: relative; on it and when i seem to remove that it fixes it. it also fixes it when i give the button z-index: 99; (or simply just a high z-index). I have nothing such as z-index making one appear above/below the other, so i'm simply lost on this I'd appreciate if anyone knows anything. Thanks in advance.
No description
32 Replies
ἔρως
ἔρως2mo ago
please, make a codepen or jsfiddle where we can see the issue ourselves
snxxwyy
snxxwyyOP2mo ago
i can try figure something out but i put the same snippet of stuff into codepen and it doesn't replicate the problem, i mentioned this.
ἔρως
ἔρως2mo ago
then that's where you start your debugging adventure and add more code then you take off some code, and see if it is still broken until you get to the point where the bug happens but doesn't if you remove a line or until you don't know but have a reasonable amount of code
snxxwyy
snxxwyyOP2mo ago
ah i managed to re-create it, sorry. so essentially if .container has a background color, it hides the focus outline? is this normal behavior? and would you say adding a z-index is a good fix or not really? https://codepen.io/deerCabin/pen/oNKqagz
ἔρως
ἔρως2mo ago
weirdly enough, it's the position: relative that's causing it
snxxwyy
snxxwyyOP2mo ago
yeah that's what's baffling me haha i'm not really sure how that causes that
ἔρως
ἔρως2mo ago
me too, a little and i have no idea either but since you don't need it, just remove it
snxxwyy
snxxwyyOP2mo ago
this is just a snippet as i say, there's an absolute element tied to it in the project so unfortunately i need to keep it
ἔρως
ἔρως2mo ago
how about you do the nasty thing of putting it all inside another div that has the position relative?
ἔρως
ἔρως2mo ago
No description
ἔρως
ἔρως2mo ago
i don't like it, but it works
snxxwyy
snxxwyyOP2mo ago
yeah that seems to do it. Thanks for helping do you think the conflict with relative is a bug? or just a weird behaviour
ἔρως
ἔρως2mo ago
actually, it doesn't, because the x still gets on top of it ...
ἔρως
ἔρως2mo ago
No description
snxxwyy
snxxwyyOP2mo ago
hm do you think position: relative gives the div a higher z-index?
ἔρως
ἔρως2mo ago
it probably is doing something funky to create a new context i found a much better fix, that is also worse
snxxwyy
snxxwyyOP2mo ago
what's that?
ἔρως
ἔρως2mo ago
No description
ἔρως
ἔρως2mo ago
change nothing on your code, and add position: relative; z-index: 1; to your button
snxxwyy
snxxwyyOP2mo ago
ah i see. so if adding position: relative; to the button also fixes it it must be a stacking context thing as you say.
snxxwyy
snxxwyyOP2mo ago
No description
snxxwyy
snxxwyyOP2mo ago
Stack Overflow
Why position: relative without z-index creates a new stacking context?
From this article: Two elements with the same stack level are layered based on their source order. Successive elements stack on top of their predecessors. And from this: A stacking context is
snxxwyy
snxxwyyOP2mo ago
this'll most likely be it
ἔρως
ἔρως2mo ago
it doesn't fix it, but it's half the way there you do need the z-index: 1 for it to draw on top of the other element
snxxwyy
snxxwyyOP2mo ago
oh okay i see.
ἔρως
ἔρως2mo ago
but try it yourself, you will see
ἔρως
ἔρως2mo ago
No description
No description
ἔρως
ἔρως2mo ago
if you notice, all i changed was the z-index
snxxwyy
snxxwyyOP2mo ago
ah i see, yeah.
ἔρως
ἔρως2mo ago
it's weird, but it is what it is
snxxwyy
snxxwyyOP2mo ago
Yeah. How do you recommend going about debugging these sorts of things? That doesn’t seem like an expected behaviour you’d imagine, so I gather those things are very hard to debug
ἔρως
ἔρως2mo ago
exactly how i told you: - grab everything you have - shove it somewhere - delete code until it works - go back until it doesnt - repeat until you find what is causing the bug there's no magic to it: just grunt work and brute force your way to the solution obviously, you can use your knowledge of the code to reduce the code more effectivelly with each iteration
Want results from more Discord servers?
Add your server