I need to make a hover in a paragraph and change the color of the link tag, how can I do this?
p:hover a {
color:red;
}
<a href="#">Título</a>
<p>Passar o mouse troca a cor do link acima</p>
I need to make a hover in a paragraph and change the color of the link tag, how can I do this?
p:hover a {
color:red;
}
<a href="#">Título</a>
<p>Passar o mouse troca a cor do link acima</p>
In css there is no way to change the color of the previous item just to change the color of the items abaixo
of the dentro
of the element, I suggest you change the order of the elements so that you can use the +
marker css
.
The marked +
select the next element defined after it as in the example below:
a:hover + p {
color: red;
}
<a href="">hover me</a>
<p> change color<p>
Summary: When you enable hover
in element a
, change the color of the p
element that follows.
However you can do this with javascript/jquery
using the prev()
function:
$('p:hover').prev('a').css('color', 'red');
In this order - the element with hover
affects a previous element is not possible, only a later one. But since what matters is the order in html, nothing prevents you from changing the visual positioning via CSS.
p:hover + a {
color:red;
background-color: yellow;
}
<p>Passar o mouse troca a cor do link acima</p>
<a href="#">Título</a>