1

I have this annoying problem with padding. I am building a menu, here is the html code for it (I have taken out all the other tabs and leave only one for better readability):

<div id="menu">
    <a class="<?php echo $description; ?>" href="<?php echo $path; ?>">Opis</a>
</div>

$description can take two values:

  1. selected
  2. notSelected

And the $path is just for correct relative addressing.

Here is the CSS code:

#menu {
    font-family: "Lucida Sans", "Lucida Sans Regular", "Lucida Grande", "Lucida Sans Unicode", Geneva, Verdana, sans-serif;
    background-color: #1958b7;
    padding: 0 0 20px 0;    /*Here set the size for tabs.*/
    border-top: 10px #2175bc solid; /*Here we add border.*/
}

#menu a {
    color: #fff;    /*White color. */
    text-decoration: none;  /*No decoration.*/
    padding: 0px 9px 5px 9px;   /*The padding for tab.*/    
}
.selected {
    border-left: 8px solid #5ba3e0; /*Defining color and width for left border.*/
    border-right: 8px solid #5ba3e0;    /*Defining color and width for right border.*/
    background-color: #2586d7;
}
.notSelected {
    border-left: 8px solid #1958b7;
    border-right: 8px solid #1958b7;
    background-color: #2175bc;
}

Now the problem is with padding from #menu a:

padding: 0px 9px 5px 9px;   /*The padding for tab.*/

In Opera, Chrome, IE7, IE8 and IE9 it works properly, the result is this:

The right result.

But in Firefox 4.0.1 (and I remember this was also a problem with FF 3.6) it displays like this:

The wrong result.

As you can see, the FF puts 1px above tag Opis for no reason, even though I have defined explicitly not to put any padding on top. So now that 1px of strong blue color is visible on top of tab.

Jernej Jerin
  • 3,179
  • 9
  • 37
  • 53

2 Answers2

3

Although it works fine for me in Ff 3.6.17 up-to FF 5.0, this can happen from whitespace between the tags.

workarounds (any one of the following) that should help

  1. remove the whitespace
    <div id="menu"><a class="<?php echo $description; ?>" href="<?php echo $path; ?>">Opis</a><div>

  2. set #menu{font-size:0px;line-height:0;} and reset those properties to what you want for the links #menu a{font-size:12px;line-height:12px;}

  3. float the links inside the #menu with #menu a{float:left;}

Gabriele Petrioli
  • 191,379
  • 34
  • 261
  • 317
  • Just to let you know, testing your demo with Firefox 4.0.1 / Windows 7, if I resize the "Result" iframe, the gap appears like in the screenshot in my answer. – thirtydot May 12 '11 at 09:12
  • The link that you posted, I took a look and I have that gap just as in my example. Maybe you overlooked it, because it just 1px in height. Tried your recommendations, 1. solution I have thought about it before I posted here and also tried it, does not work, so the whitespaces are not the problem. 2. solution, set the font-size: 17px and line-height: 19px. Now about this solution the problem is that now in IE7, IE8, IE9 the tag is now over 1px, so there is no more gap, but it is now higher. Continue in next post: – Jernej Jerin May 12 '11 at 12:41
  • So this solution does fix FF, but now breaks IE. 3. solution is what I was looking for, it works in all the browsers, after adding float: left I only had to increase padding in #menu to padding: 0 0 30px 0, because for some reason it has shortend it. Thanks for help. – Jernej Jerin May 12 '11 at 12:41
2

It sometimes (the gap only appears when I resize the jsFiddle iframe [??]) looks like this in my Firefox 4:

http://jsfiddle.net/tvHgX/

so, there is a gap, but it doesn't look exactly like your screenshot.

I fixed the gap to never appear by adding float: left to #menu a. I also replaced your line:

padding: 0 0 20px 0;    /*Here set the size for tabs.*/

with overflow: hidden, to clear the floats so you don't have to manually specify padding. You can revert this fix if you like.

Complete code: http://jsfiddle.net/tvHgX/1/

display: inline-block would also work in place of float: left if you don't want to use floats for some reason.

thirtydot
  • 224,678
  • 48
  • 389
  • 349
  • Thanks, yeah I used then float: left from the first answear, just as you proposed. About padding, I need to have height custom defined, becuase I want to have lower bottom in blue. Look here what I mean: http://www.vp-zalec.net/podatki/ – Jernej Jerin May 12 '11 at 12:47