Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    Senior Coder
    Join Date
    Jun 2008
    Location
    New Jersey
    Posts
    2,535
    Thanks
    45
    Thanked 259 Times in 256 Posts

    Sprites acting strangely in fixed element

    As I'm sure most people are, whenever I have a menu with a number of images and/or states, I like to use a common sprite. I have a sprite built consisting of 6 images with 2 states each. I have them as the background images of a set of anchor tags within a nav. This nav is then given a fixed position.

    Now the problem: when the position is fixed, the sprites seem to shift off position, making it look bad. This is best explained by example:

    Sprites acting strangely in fixed element-error.jpg

    As you can see, the image just below the gray line has a faint line to the left of it; this is the right edge of the image above. Likewise, you can see that the image on the right is one pixel lower then the one on the right. 3 of the icons shift down by 1 pixel, 3 up. When I remove the fixed positioning, the bleeding doesn't occur. Clearly that's something from a fixed position, but I don't know what.

    However, removing the fixed position doesn't fix the 1px up/down. I've sliced the image in Photoshop to confirm they overlay correctly; they do.

    I'm at a loss for fixing either of these problems. The fixed position issue is a bigger deal to me; I don't think most people will notice the 1px shift, but it does bother me, so any help there would be appreciated as well.

    The CSS:
    Code:
    #navMenu {
    	position: fixed;
    	top: 55px;
    	right: 50%;
    	width: 60px;
    	margin-right: 415px;
    }
    
    #navMenu a {
    	display: block;
    	width: 35px;
    	height: 35px;
    	margin: 15px auto;
    	background: url('../images/bodyComponents/menu.png') top left no-repeat;
    }
    
    #navMenu .home {
    	background-position: 0 0;
    }
    
    #navMenu .forms {
    	background-position: -35px 0;
    }
    
    #navMenu .forums {
    	background-position: -70px 0;
    }
    
    #navMenu .calendar {
    	background-position: -105px 0;
    }
    
    #navMenu .roster {
    	background-position: -140px 0;
    }
    
    #navMenu .settings {
    	background-position: -175px 0;
    }
    
    #navMenu .home:hover {
    	background-position: 0 -35px;
    }
    
    #navMenu .forms:hover {
    	background-position: -35px -35px;
    }
    
    #navMenu .forums:hover {
    	background-position: -70px -35px;
    }
    
    #navMenu .calendar:hover {
    	background-position: -105px -35px;
    }
    
    #navMenu .roster:hover {
    	background-position: -140px -35px;
    }
    
    #navMenu .settings:hover {
    	background-position: -175px -35px;
    }
    The HTML
    Code:
    	<nav id="navMenu">
    		<a href="" class="home" title="Home" alt="Home"></a>
    		<a href="" class="forms" title="Forms" alt="Forms"></a>
    		<a href="" class="forums" title="Forums" alt="Forums"></a>
    		<a href="" class="calendar" title="Calendar" alt="Calendar"></a>
    		<a href="" class="roster" title="Roster" alt="Roster"></a>
    		<a href="" class="settings" title="Settings" alt="Settings"></a>
    	</nav>
    The sprite:
    Sprites acting strangely in fixed element-menu.png

  • #2
    Master Coder Excavator's Avatar
    Join Date
    Dec 2006
    Location
    Alaska
    Posts
    9,675
    Thanks
    22
    Thanked 1,827 Times in 1,811 Posts
    Hello Keleth,
    I could not reproduce your problem with the information you've provided.
    Maybe a link to a test site would be best, as well as what browser is giving you trouble.

    This works fine in IE11 and FF28
    Code:
    <!DOCTYPE HTML>
    <html>
    <head>
    <meta charset="UTF-8">
    <title>Untitled Document</title>
    <style type="text/css">
    html, body {
    	margin: 0;
    	font: 100% "Trebuchet MS", Arial, Helvetica, sans-serif;
    	color: #000;
    	background: #fc6;
    }
    #container {
    	width: 800px;
    	margin: 0 auto;
    	background: #999;
    }
    #navMenu {
    	position: fixed;
    	top: 55px;
    	right: 50%;
    	width: 60px;
    	margin-right: 415px;
    }
    #navMenu a {
    	display: block;
    	width: 35px;
    	height: 35px;
    	margin: 15px auto;
    	background: url(menu.png) top left no-repeat;
    }
    #navMenu .home { background-position: 0 0; }
    #navMenu .forms { background-position: -35px 0; }
    #navMenu .forums { background-position: -70px 0; }
    #navMenu .calendar { background-position: -105px 0; }
    #navMenu .roster { background-position: -140px 0; }
    #navMenu .settings { background-position: -175px 0; }
    #navMenu .home:hover { background-position: 0 -35px; }
    #navMenu .forms:hover { background-position: -35px -35px; }
    #navMenu .forums:hover { background-position: -70px -35px; }
    #navMenu .calendar:hover { background-position: -105px -35px; }
    #navMenu .roster:hover { background-position: -140px -35px; }
    #navMenu .settings:hover { background-position: -175px -35px; }
    </style>
    </head>
    <body>
        <div id="container">
    		<nav id="navMenu">
    			<a href="" class="home" title="Home"></a>
    			<a href="" class="forms" title="Forms"></a>
    			<a href="" class="forums" title="Forums"></a>
    			<a href="" class="calendar" title="Calendar"></a>
    			<a href="" class="roster" title="Roster"></a>
    			<a href="" class="settings" title="Settings"></a>
    		</nav>
        <!--end container--></div>
    </body>
    </html>
    I did remove invalid alt.
    Validate often DURING development - Use it like a splelchecker | Debug during Development |Write it for FireFox, ignore IE
    Use the right DocType | Validate your markup | Validate your CSS | Why validating is good | Why tables are bad


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •