1

When I hover over the text, the text moves. The reason that the text is moving is that I remove the bold effect on hover. How to stop the text to move on hover?

#menu li a{
    color:#595959;
    font-size:14px;
    font-weight:bold;
    position: relative; 
    overflow:hidden;
    padding:2px 5px;
}

#menu li a:hover{
    color:#FFFFFF;  
    font-weight:normal;
    background-color:#e11d3b;
    -webkit-border-radius: 5px;
    -moz-border-radius: 5px;
    border-radius: 5px; 
    text-decoration:none;   
}
user2632980
  • 531
  • 3
  • 8
  • 23

3 Answers3

1

It seems that the only way you can avoid this is setting the width fixed. (of each li element)

If not, the bold will always move your text..

Lan
  • 709
  • 1
  • 8
  • 16
0

Well, by being shorter without bold, it's mathematic that the text will appear to move, since it does not have the same size anymore... by doing something like that:

#menu li a{
    color:#595959;
    font-size:14px;
    font-weight:bold;
    position: relative; 
    overflow:hidden;
    padding:2px 5px;
    font-size: 25px;
    display: block;
    width: 180px;
    text-align:center;
}

#menu li a:hover{
    color:#FFFFFF;  
    font-weight:normal;
    background-color:#e11d3b;
    -webkit-border-radius: 5px;
    -moz-border-radius: 5px;
    border-radius: 5px;
}

You set a width to the link, as well as a display type block (so it will behave like a div for instance). This way, you can add a text-align: center; that will minimize the impression the text has moved.

0

add this to your css #menu li a:hover{padding:2px 5px 2px 6px;}

Demo

Abdul Malik
  • 2,632
  • 1
  • 18
  • 31