The forums ran from 2008-2020 and are now closed and viewable here as an archive.

Home Forums CSS [Solved] Additional padding being added on a:hover

  • This topic is empty.
Viewing 3 posts - 1 through 3 (of 3 total)
  • Author
  • #26895

    Hi all,

    I’m working on navigational links today and I’m running into an issue when trying to change the background on the a:hover state.

    I have the navigation displaying a background image initially, then on hover, change to the color #fff. For some reason, when I hover over the link extra padding is being added to the left and right of the link.

    Here is the CSS for this section:

    ul#navigation { list-style-type: none; width: 100%; font-family : Georgia, Times, serif; font-size : 1.25em; font-weight : regular; text-align: left; }

    ul#navigation li { display: inline; background: url(images/nav-inactive-li-bg.gif) repeat-x; height: 26px; padding: 3px 15px 3px 15px; margin: 0 5px 0 0; }

    ul#navigation li a { color: #2F2626; text-decoration: none;}
    ul#navigation li a:hover { background: #fff; height: 26px; padding: 3px 15px 3px 15px;}

    Here is a link to the page:

    Any suggestions are greatly appreciated.



    This is occurring because at first you are applying the background to the <li>, but then on the hover you’re applying it to the <a>, you should really pick one of those and stick with it throughout. In this case, I would always have the background image on the <a>.

    You may not need to actually use Sprites in this particular case, but the code Chris uses should help you figure out what elements to put the styling on (it can be confusing for sure):


    Ah, that makes perfect sense. It works as it should now.


Viewing 3 posts - 1 through 3 (of 3 total)
  • The forum ‘CSS’ is closed to new topics and replies.