Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Possible to style other element on :focus?

Is it possible to style another element on :focus of a specific element?

Something like:

input:focus #header {
    display: none;
}

I tried doing that but it didn't work.

like image 602
Kid Diamond Avatar asked Apr 18 '14 12:04

Kid Diamond


People also ask

How do you apply style to several specific element types?

You will begin by using the type selector to select HTML elements to style. Then, you will combine selectors to identify and apply styles more precisely. Lastly, you will group several selectors to apply the same styles to different elements.

Does focus work on div CSS?

As per the spec: The :focus pseudo-class applies while an element has the focus (accepts keyboard events or other forms of text input). The <div> does not accept input, so it cannot have :focus . Furthermore, CSS does not allow you to set styles on an element based on targeting its descendants.

What elements can be focused HTML?

Elements of the following type are focusable if they are not disabled: input , select , textarea , button , and object . Anchors are focusable if they have an href or tabindex attribute. area elements are focusable if they are inside a named map, have an href attribute, and there is a visible image using the map.


1 Answers

Yes,it is possible if element is a sibling or a child to the :focus element. If it is not your case (affect whatever you want) than you should use javascript.

like image 114
potashin Avatar answered Oct 29 '22 12:10

potashin