user1737587
user1737587

Reputation: 79

CSS on hover enlarge <li> and move text position

here is what i managed to do..

http://jsfiddle.net/pns2050/gAZPs/3/

#navigation ul li {
    text-decoration: none;
    list-style:none;
    text-align:center;
    float:left;
    width:80px;
    height:30px;
    margin-left:10px;
    border-bottom-left-radius:10px;
    border-bottom-right-radius:10px;
    background-image:url(../images/nav.jpg);
    box-shadow: 0px 2px 5px 2px #91948d;

}

#navigation ul li a {
    margin-top:5px;      
    text-decoration: none;
    color:white;
    font-weight:bold;
    width:100%;
    height:100%; 
    display:block;
}

#navigation ul li:hover
{
 height:33px;
}

#navigation ul li a:hover {
    margin-top: 8px;

}

The problem i have is that on hover if i have my mouse on the top side of the "box" the text returns to its original position .. i have set [ul li a] to height:100% but i dont get it why it doesnt work..

any help will be appreciated , thank you

Upvotes: 0

Views: 1695

Answers (2)

jgthms
jgthms

Reputation: 864

If you want the whole element to be clickable, don't style the libut style the a directly!

Demo: http://jsfiddle.net/gAZPs/5/

Use display:inline on the li to remove the bullets:

#navigation ul li {
    display:inline;   
}

Then, use all your styles on the a:

#navigation ul li a{
    text-decoration: none;
    text-align:center;
    float:left;
    width:80px;
    height:30px;
    margin-left:10px;
    border-radius:0 0 10px 10px;
    background-color:#ccc;
    box-shadow: 0px 2px 5px 2px #91948d;
    color:white;
    font-weight:bold;
    line-height: 30px;
}


 #navigation ul a:hover {
    padding-top: 3px;
}

Upvotes: 1

Viktor S.
Viktor S.

Reputation: 12815

Just change

 #navigation ul li a:hover {
        margin-top: 9px;

    }

to

#navigation ul li:hover a {
    margin-top: 9px;

}

Upvotes: 2

Related Questions