Almost :)
There is a css selector for adjacent elements, the +
, but it only works for elements that are next. And not like your case before.
Further note that the element span
is an element inline
by definition, so that you can position it vertically display: block;
for example.
But if HTML can be changed from order, then:
label {
display: block;
padding: 20px;
}
.grupo-input span {
transition: margin-top .5s;
margin-top: 0px;
display: block;
}
.grupo-input input:hover + span {
margin-top: -40px;
}
<label class="grupo-input">
<input type="text" name="filtro_nome">
<span>Nome</span>
</label>
jsFiddle: https://jsfiddle.net/g06s90jk/
If you want you could have both hover
and the focus
not to be calmer: https://jsfiddle.net/g06s90jk/1/
Not.
– Bacco
CSS has element selectors arranged sequentially, but they are always valid for the latter, and do not affect the former (the input cannot affect what comes before it). It would be nice if you exposed the problem or end effect you want to make, the best solution not always the way you imagine. You can [Dit] the question and explain how is the effect you want to do, and maybe we can think of a better structure to get the result.
– Bacco
Our friend answered right there in the post, it was exactly that. Thank you very much man!
– Pedro Soares
Even so, it is always good to get the question as clear as possible, so that it helps other people with the same problem. Remembering that the more detailed the question, the more chance you have of getting a variety of answers with interesting proposals (you’re not always lucky enough for someone as experienced as @Sergio to post an answer that matches what you need). For the next ones, there are some cool tips here: [Ask]. And I’m glad this one worked out already!
– Bacco