: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
ἔρως
ἔρως3w ago
please, make a codepen or jsfiddle where we can see the issue ourselves
snxxwyy
snxxwyyOP3w 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.
ἔρως
ἔρως3w 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
snxxwyyOP3w 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
ἔρως
ἔρως3w ago
weirdly enough, it's the position: relative that's causing it
snxxwyy
snxxwyyOP3w ago
yeah that's what's baffling me haha i'm not really sure how that causes that
ἔρως
ἔρως3w ago
me too, a little and i have no idea either but since you don't need it, just remove it
snxxwyy
snxxwyyOP3w 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
ἔρως
ἔρως3w ago
how about you do the nasty thing of putting it all inside another div that has the position relative?
ἔρως
ἔρως3w ago
No description
ἔρως
ἔρως3w ago
i don't like it, but it works
snxxwyy
snxxwyyOP3w 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
ἔρως
ἔρως3w ago
actually, it doesn't, because the x still gets on top of it ...
ἔρως
ἔρως3w ago
No description
snxxwyy
snxxwyyOP3w ago
hm do you think position: relative gives the div a higher z-index?
ἔρως
ἔρως3w ago
it probably is doing something funky to create a new context i found a much better fix, that is also worse
snxxwyy
snxxwyyOP3w ago
what's that?
ἔρως
ἔρως3w ago
No description
ἔρως
ἔρως3w ago
change nothing on your code, and add position: relative; z-index: 1; to your button
snxxwyy
snxxwyyOP3w 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
snxxwyyOP3w ago
No description
snxxwyy
snxxwyyOP3w 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
snxxwyyOP3w ago
this'll most likely be it
ἔρως
ἔρως3w 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
snxxwyyOP3w ago
oh okay i see.
ἔρως
ἔρως3w ago
but try it yourself, you will see
ἔρως
ἔρως3w ago
No description
No description
ἔρως
ἔρως3w ago
if you notice, all i changed was the z-index
snxxwyy
snxxwyyOP3w ago
ah i see, yeah.
ἔρως
ἔρως3w ago
it's weird, but it is what it is
snxxwyy
snxxwyyOP3w 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
ἔρως
ἔρως3w 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