Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Anchor tag change image on hover and active

Tags:

html

css

anchor

I am trying to change the anchor tag image on hover and active, but it is not working.

HTML:

<div>
    <div id="accordion">
        <h3><a href="" runat="server" id="aCollection">test</a></h3>
        <div class="acsection" runat="server" id="divCollection">
            <ul>
                <li runat="server" id="collectionmenu1"><a href="1.aspx">page-1</a></li>
                <li runat="server" id="collectionmenu2"><a href="2.aspx">page-2</a></li>
                <li runat="server" id="collectionmenu3"><a href="3.aspx">page-3</a></li>
                <li runat="server" id="collectionmenu4"><a href="4.aspx">page-4</a></li>
            </ul>
        </div>
    </div>
    <h3><a href="5.aspx">Group</a></h3>
    <h3><a href="6.aspx">Send</a></h3>
    <h3><a href="7.aspx">contact</a></h3>
</div>

CSS:

#aCollection
{
    background-image: url(images/collection.jpg);
}

#aCollection:hover
{
    background-image: url(images/collection_hover.jpg);
}

#aCollection:active
{
    background-image: url(images/collection_active.jpg);
}
like image 654
sam Avatar asked Aug 06 '11 15:08

sam


2 Answers

Try this one. it's working :). just add src= for the hover image and when the mouse out also add src=.

<a href="#"><img src="blah.jpg" onMouseOver=src="blah-hover.jpg" onMouseOut=src="blah.jpg"></a>
like image 79
carl Avatar answered Sep 29 '22 06:09

carl


A tag is a inline element. You need a block element.

#aCollection {
     display: block;
     width: 50px;
     height: 50px;
     background: url('../images/image.jpg') no-repeat top left;
}
#aCollection:hover {
     background-image: url('../images/image_hover.jpg');
}
#aCollection:active {
     background-image: url('../images/image_active.jpg');
}
like image 38
blejzz Avatar answered Sep 29 '22 06:09

blejzz