0

I have a webpage made with svelte and I am trying to create a sort of tooltip for a div that should be displayed on hover.

So I wrote this:

<div
  class="test"
  style="background-color: {testcase.failure ? 'red' : 'green'}"
  on:mouseenter={() => (testcase.mouseover = true)}
  on:mouseleave={() => (testcase.mouseover = false)}>
  {#if (testcase.failure && testcase.mouseover)}
    <div class="failure">
      <div class="name">{testcase.class}:{testcase.name}</div>
      <div class="error">{testcase.failure}</div>
    </div>
  {/if}
</div>

and it works in the sense that the failure div is shown only on hover. However it is of course shown underneath all elements that are "after" it in the DOM.

So I added a z-index to failure, but it does nothing. It is still displayed underneath everything despite having a much higher z-index.

After experimenting a bit I figured out that if I remove the if statement and simple always display the failure div, then it is "properly" displayed on top of everything else.

This seems really weird for me and I cannot figure out why it does this. Does anyone have any good explanation for it? (I know that I can probably always display it and just change opacity or something to get the same effect, but I am curious about the root cause)

munHunger
  • 2,572
  • 5
  • 34
  • 63

0 Answers0