Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why changing visibility/display on focus does not work?

Tags:

html

css

I've gotten an idea to make a search "button" upon clicking which the input box would show up and stretch. However instead of using an invisible checkbox I decided to try and use the label since clicking the label would put focus on the element the label is connected to. And while giving focus and doing basic transformations do work, I can't seem to hide/show the textbox either using visibility: hidden/visible or display: none/inline-block. And I don't want to just rely on opacity since the textbox can be found/clicked even while it's hidden.

Current attempt: JsFiddle

Why doesn't this work? What am I doing wrong?

like image 822
MrPlow Avatar asked Jan 25 '14 14:01

MrPlow


People also ask

Can you focus an element with display none?

There is a button to toggle the visibility ( display ) of the focusable element, but before showing the element, it attempts to programmatically focus it. Focusing a display:none element is not expected to work, but the issue is what follows. Once the element is shown, no future attempt to focus the element will work.

What is the difference between visibility and display?

Your answervisibility:hidden- It is not visible but gets up it's original space whereas, display:none- It is hidden and takes no space.

Does display none improve performance?

Display none don't reduce the size of the dom, just make the element not visible, like visible hidden, without occupies the visual space. Display none don't improve the performance because the goal of virtual scrolling is reduce the number of the elements into the dom.

Can Li be focused?

You cannot normally focus li elements. But you can hover them, so you should use li:hover instead of li li:focus .


1 Answers

Elements that are not visible cannot receive focus, therefore the :focus psuedo-class cannot apply.

Using width and opacity seems to produce a reasonable effect.

like image 89
Niet the Dark Absol Avatar answered Sep 21 '22 15:09

Niet the Dark Absol