Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

CSS - Text moves when hovering

Tags:

html

css

hover

move

I've been at this for about an hour now, and cant seem to grip it.
Everytime I hover over this text (I'm wanting to put a background color for it to hover), the text moves, along with the bgcolor. Here is what I got:

        #innerheader ul {
            list-style:none;
            margin:0;
            padding:0;
        }
        #innerheader li {
            display:block;
            float:left;
            height:25px;
            margin:0 2px;
            padding:15px 10px 0 10px;
            color:#FFFFFF;
            font-weight:bold;
            font-size:10px;
            text-transform:uppercase;
        }

        #innerheader li a, 
        #innerheader li a:link, 
        #innerheader li a:visited, 
        #innerheader li a:active {
            color:#FFFFFF;
            text-decoration:none;
        }
        #innerheader li a:hover {
            background-color: blue;
            padding: 10px 10px 10px 10px
        }
like image 661
Ben Dover Avatar asked Dec 13 '11 02:12

Ben Dover


People also ask

What is CSS hover effect?

What is a CSS Hover Effect? A CSS hover effect takes place when a user hovers over an element, and the element responds with transition effects. It is used to mark the key items on the web page and it's an effective way to enhance the user experience.

How do I stop my mouse from hovering CSS?

To remove the CSS hover effect from a specific element, you can set the pointer-events property of the element (the hover behavior of which you want to disable) to “none”.


2 Answers

Remove the padding in the hover declaration. Or simply move the padding to the anchor before the hover state, like the code below.

The reason the text is moving is there is no padding on the anchor, then when you hover, there's padding.

#innerheader li a, 
    #innerheader li a:link, 
    #innerheader li a:visited, 
    #innerheader li a:active {
        color:#FFFFFF;
        text-decoration:none;
        padding: 10px;
    }
    #innerheader li a:hover {
        background-color: blue;
    }
like image 118
Scott Avatar answered Nov 15 '22 01:11

Scott


It's because of padding. Remove it then it will work just fine.

like image 40
chhantyal Avatar answered Nov 15 '22 01:11

chhantyal