W
W
Wasya UK2018-02-04 11:59:30
css
Wasya UK, 2018-02-04 11:59:30

How to apply style to parent or closest?

How can I apply styles to the label when the input is focused?
Here I threw it ...
Thanks in advance.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
J
Jaroslaw Goszowski, 2018-02-04
@dmc1989

1) Wrap the input and label of the wrapper with position: relative;
2) Padding on top to fit the label
3) The label itself is position absolute; top: 0;
4) But actually we put the label right after the input
5) For the input we write: input:focus+label {color: red}

S
Stalker_RED, 2018-02-04
@Stalker_RED

No way. If you rearrange the label below in the code, you can use sibling selectors (~ or +).
Otherwise, only scripts.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question