Jens Eeckhout
Jens Eeckhout

Reputation: 155

Unwanted margin in all browsers except Firefox

So, I've started working out some basics for my portfolio site. I've finished the navigation bar, but now when testing cross-browser, it shows a few pixels of margin underneath the navigation. This happens in all browsers except Firefox. Which kinda confuses me, since the elements all have absolute positioning.

HTML:

<div id="topnav">
    <ul>
        <li><a href="index.html" id="current">Home</a></li>
        <li><a href="about.html">About Me</a></li>
        <li><a href="portfolio.html">Portfolio</a></li>
        <li><a href="contact.html" class="lastli">Contact Me</a></li>
    </ul>
</div>

This div is inside a container, which has 800 width, margin 20px top and auto on the sides. The padding and margin is set to 0. The "top:195" is to position the bar under my header image (which is 800x195). Also note: the list items have a 1x20 background gradient image, that's set to repeat-x.

CSS:

#topnav {
    width:800px;
    position:absolute;
    top:194px;
    height:20px;
}

#topnav ul {
    list-style-type:none;
    text-align:center;
    height:20px;
    margin:0;
    padding:0;
}

#topnav ul li {
    display:inline;
    font-size:15px;
    line-height:20px;
}

#topnav ul li a {
    padding:0 10px;
    position:relative;
    border-left:1px solid white;
    margin-left:-6px;
}

Note, I have tried setting the height to 20px on several occasions, but none seem to have any effect. I have changed the fonts as well, to no avail. Screenshots here: https://i.sstatic.net/rzU3E.jpg Top is Firefox (and as I want it to be), bottom is Chrome. Here's a JSFiddle: http://jsfiddle.net/SUmF7/

Upvotes: 0

Views: 329

Answers (3)

Lucy Lou
Lucy Lou

Reputation: 246

Try adding display: inline-block to your tab element. Both the topnav li and a are set as inline elements, which means they won't expand to the dimensions you've set properly.

Upvotes: 0

Brighty
Brighty

Reputation: 393

Have you tried setting setting a position style on your container div?

Upvotes: 0

Emanuele Greco
Emanuele Greco

Reputation: 12721

Have you tried to put CSS reset in your stylesheet?

/* http://meyerweb.com/eric/tools/css/reset/ 
 v2.0 | 20110126
 License: none (public domain)
*/

html, body, div, span, applet, object, iframe,
h1, h2, h3, h4, h5, h6, p, blockquote, pre,
a, abbr, acronym, address, big, cite, code,
del, dfn, em, img, ins, kbd, q, s, samp,
small, strike, strong, sub, sup, tt, var,
b, u, i, center,
dl, dt, dd, ol, ul, li,
fieldset, form, label, legend,
table, caption, tbody, tfoot, thead, tr, th, td,
article, aside, canvas, details, embed, 
figure, figcaption, footer, header, hgroup, 
menu, nav, output, ruby, section, summary,
time, mark, audio, video {
margin: 0;
padding: 0;
border: 0;
font-size: 100%;
font: inherit;
vertical-align: baseline;
}
/* HTML5 display-role reset for older browsers */
article, aside, details, figcaption, figure, 
footer, header, hgroup, menu, nav, section {
display: block;
}
body {
line-height: 1;
}
ol, ul {
list-style: none;
}
blockquote, q {
quotes: none;
}
blockquote:before, blockquote:after,
q:before, q:after {
content: '';
content: none;
}
table {
border-collapse: collapse;
border-spacing: 0;
}

Upvotes: 1

Related Questions