0
0
0348raven2015-11-19 21:32:39
css
0348raven, 2015-11-19 21:32:39

The task at focus to change style of the next block?

I have the following code

<div class="1">
      <span class="2">Цена, например</span>
      <input class="3" type="text"/>
</div>

It is necessary to change the color of the span with the class "2" with focus on the input + the styles of the input itself too.
I tried wrapping it all in a label and a form, it didn't work.
Perhaps removing the span tag would work?
Thanks in advance!

Answer the question

In order to leave comments, you need to log in

2 answer(s)
W
wellgo, 2015-11-19
@wellgo

Swap input with span, then you can do this:

input:focus + span {
    color:#f00;
}

Unfortunately CSS does not allow selecting the "previous" element

L
LeXX2012, 2015-11-19
@LeXX2012

If you can not swap, then only js

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question