Reputation: 33
Im trying to change the hover colour of a rectangle shape which ive made a link.
The html is
<a href='page1.html'>
<div class="tri">
</div>
</a>
and the css is
.tri {
width:100px;
height:200px;
background: #b51e4c;
position:absolute;
top:100px;
left:100px;
}
I think this is the code I need to put in
a.tri:hover { background-color: yellow;}
but its not working please help!
Upvotes: 1
Views: 48
Reputation: 7207
Try to use like this: Demo
CSS:
.tri a {
width:100px;
height:200px;
background: #b51e4c;
position:absolute;
top:100px;
left:100px;
}
.tri a:hover {
background-color: yellow;
}
HTML:
<div class="tri"> <a href='page1.html'> </a></div>
Its not good practice to use <div>
inside <a>
. So interchanged the position of both in html as well in CSS
Upvotes: 2
Reputation: 639
Your code should work correctly. Try adding the class directly to the <a>
tag. Here is the codepen demonstrating your code:
http://codepen.io/anon/pen/NPVeoP
Upvotes: 0
Reputation: 14348
You have to add space a[here].tri:hover { background-color: yellow;}
.tri {
width:100px;
height:200px;
background: #b51e4c;
position:absolute;
top:100px;
left:100px;
}
a .tri:hover { background-color: yellow;}
<a href='page1.html'>
<div class="tri">
</div>
</a>
Upvotes: 0