Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

in Firefox, click on absolute element inside focusable element does not focus focusable element unless it has a CSS position

Context: an absolute element inside a focusable element.

In Firefox 36, if the focusable element does not have a CSS position (relative, fixed, or absolute), a click on the inside element will not set focus to the focusable element...

Any idea whether that is a known bug?

Not reproductible on IE11 and Chrome.

For better understanding of the issue, here's an example:

Codepen

/* this is just so that the squares are similarly displayed */
section {
  position: relative;
  display: inline-block;
  margin-right: 75px;  
}

div {
  background-color: red;
  width: 100px;
  height: 100px;
  color: white;
  padding: 5px;
}

div:focus {
  background-color: green;
}

div > span {
  position: absolute;
  display: inline-block;
  top: 50px;
  left: 50px;
  background-color: blue;
  width: 100px;
  height: 100px;
  padding: 5px;
}
Context: an absolute element inside a focusable element.<br>
In  Firefox 36, if the focusable element does not have a "position: relative", a click on the inside element will not set the focus on the focusable element...<br>
(red block turns green when focused)
<br><br>
Edit: none works in IE
<br><br>

<section>
  <div style="position: relative;" tabindex="-1">
    With position: relative
    <span>
      click here
    </span>
  </div>
</section>

<section>
  <div tabindex="-1">
    With no position
    <span>
      click here
    </span>
  </div>
</section>
like image 345
jlowcs Avatar asked Feb 27 '15 19:02

jlowcs


People also ask

How do you make an element not focusable in CSS?

In order to make an prevent an element from taking focus ("non-focusable"), you need to use Javascript to watch for the focus and prevent the default interaction. In order to prevent an element from being tabbed to, use tabindex=-1 attribute. Adding tabindex=-1 will make any element focusable, even div elements.

How do you make a focusable element in HTML?

You can make it focusable by adding a tabindex=0 attribute value to it. That will add the element to the list of elements that can be focused by pressing the Tab key, in the sequence of such elements as defined in the HTML document.


1 Answers

In this case, the click event is fired and event propagation will takes place. So click on the inside element will propagate to the parent element and the parent will get focus and style will be applied. For more details go through event propagation event propagation

like image 131
Mr_Perfect Avatar answered Oct 02 '22 13:10

Mr_Perfect