views:

119

answers:

2

My horizontal nav bar is populated with images for the links that are coming from one image that includes all the sub-images; each nav item image is identified by the pixel location within the larger image. This works perfectly fine in Firefox and Safari, but in IE, all of the images are misplaced too low within the nav bar (can only barely see the tops of the words). Two questions:

  • How do I fix this in the css so it is back-compatible with the more recent versions (and current versions) of IE
  • Do I need a separate IE stylesheet?

Here's the css (truncated for just a few of the links):

ul#navbar {
    width: 750px;
    height: 22px;
    margin: 0px;
    padding: 0px;
    text-indent: -9999px;
    border: none;
}
ul#navbar li {
    float: left;
    height: 22px;
    margin: 0px;
    padding: 0px;
    list-style-type: none;
    border: none;
    /*position:absolute;*/
}
ul#navbar li a {
    display: block;
    height: 22px;
    border: none;
}

.home {
    left: 0px;
    width: 78px;
    background-image: url(../images/nav/new_nav.jpg);
    background-repeat: no-repeat;
    background-position: 0px 0px;
}

.classes {

    /*left: 78px; */
    width: 92px;
    background-image: url(../images/nav/new_nav.jpg);
    background-repeat: no-repeat;
    background-position: -100px 0px; 
}

.training { left: 170px; width: 89px; background-image: url(../images/nav/new_nav.jpg); background-repeat: no-repeat; background-position: -200px 0px; }

Thanks!

A: 

Well ... I think you don't want to hear this, but: Never, ever rely on exact pixel positions in HTML/CSS (imagemaps superimposed on one image are the only exception).

HTML is simply not made for pixel-exact design. From your description, there's not even a possibility for graceful fallback on browsers that don't support one of the technologies you seem to rely on. And what about screens that are too narrow to show your complete navbar (e.g. mobile devices)? In the best case, you'll get a multi-line navbar, but from your description, it would be broken since the position would be wrong...

maligree
??? Could you please elaborate what you mean by this? What aspect of using pixel positions is unreliable in CSS, and in what situations?
Pekka
`HTML is simply not made for pixel-exact design.` hobcobbles. It is perfectly possible to do pixel-exact design in HTML, and it's perfectly safe to use pixel unit values. Whether it is always *wise* is a different question. The OP's problem seems to be something very specific and related to `background-position` - which I have never had problems with to date, and I don't believe a fundamental problem exists with. We will know for sure when the OP posts some code.
Pekka
Long story about why it is this way: the short of it is that I've taken over the site from someone else and the client doesn't want to change the design at all, so I'm very limited in what I can do. To make the code better (though, believe me, it's much better than when it was in MODx). I've pulled it out and made it static.
Kim
Sorry, Pekka, but HTML was not made for pixel-exact design _originally_. It is possible now, with CSS, but in my experience it is always wise not to _rely_ on it. You'll always find another browser that handles your code a bit differently (e.g. search for "IE three pixel bug"). There are workarounds, you can get it right for a lot of use cases, but creating a dynamic design which would enable the browser to choose the best page rendering based on the clients capabilities would be the wise choice (but, I admit, it's also an art not to think in pixels but in relative measures).
maligree
The site is only 8 pages...isn't a dynamic design a bit overkill for that? To be honest, I'm pretty new at this, need to get a fix quickly, so really need a workaround for IE (yes, I realize this isn't optimal). How can I change the code to do this?
Kim
A: 
Jason Too Cool Webs
@Kim you can edit your question, better put that in there. Plus, the HTML code does not tell us anything about the underlying CSS.
Pekka
@Pekka: OK - I've added the CSS to the original comment!
Kim