1 pixel line height difference between Firefox and

2019-01-13 13:26发布

Working on a new site design in asp.net with master pages. Header of the page is a 35px tall "menu bar" which contains an asp menu control rendered as an unordered list.

The selected menu item is styled with a differenct colored background and 2px border around the left top and right sides. The bottom of the selected menu item should line up with the bottom of the menu bar so the selected "tab" looks as if it flows into the content beneath. Looks fine in firefox and IE but in chrome the "tab" seems to be 1 pixel higher than the bottom of the menu bar.

Just wondering if there is some sort of bug I dont know about.

I realize that you will most likely need code to help with this problem so ill post up the css as soon as possible.

EDIT:

here is the css for the menu...

div.hideSkiplink
{     
    width:40%;
    float:right;
    height:35px;
}

div.menu
{
    padding: 0px 0px 0px 0px;
    display:inline;
}

div.menu ul
{
    list-style: none;
}

div.menu ul li
{
    margin:0px 4px 0px 0px;
}

div.menu ul li a, div.menu ul li a:visited
{
  color: #ffffff;
  display: block;
  margin-top:0px;
  line-height: 17px;
  padding: 1px 20px;
  text-decoration: none;
  white-space: nowrap;
}

div.menu ul li a:hover
{
  color: #ffffff;
  text-decoration: none;
  border-top: 1px solid #fff;
  border-right: 1px solid #fff;
  border-bottom: none;
  border-left: 1px solid #fff;
}




div.menu ul li a:active
{
 background:#ffffff !important;
 border-top:2px solid #a10000;
 border-right:2px solid #a10000;
 border-bottom: none;
 border-left:2px solid #a10000;
 color: #000000 !important;
 font-weight:bold;

}


div.menu ul a.selected
{
  color: #000000 !important;
  font-weight:bold;
}

div.menu ul li.selected
{
 background:#ffffff !important;
 border-top:2px solid #a10000;
 border-right:2px solid #a10000;
 border-bottom: none;
 border-left:2px solid #a10000;
}

div.menu ul li.selected a:hover
{
  border: none;
}

The selected classes are added to the li and a elements via jquery...

Here is a screenshot of the problem... The chrome example is on the top and u can see 1px of red border below the tab. On the bottom is the firefox image where everything looks OK.

alt text

EDIT:

After playing around with this a bit more, I have discovered that it is actually the "header" div itself that is growing by 1px in chrome... This seems very strange to me.

16条回答
不美不萌又怎样
2楼-- · 2019-01-13 14:00

None of these answers solve the problem.

Set:

line-height: 1;
padding-top: 2px;

Because webkit & mozilla rendering engines implement line height differently do not use this it to manipulate measurement for single line items.

For items like menus, buttons and especially really small notification bubbles, reset the line-height to normal and use padding or margins to make them behave the same.

Here's a JSFiddle illustrating this issue: http://jsfiddle.net/mahalie/BSMZe/6/

查看更多
Melony?
3楼-- · 2019-01-13 14:04

I have been fighting with this problem for a little while now, and almost gave up on the pixel. However it's come to me in one of those eurika moments: if you get the tab lined up perfectly in Chrome (which leaves an overlap in Firefox), set the ul height to the height of the li (including any padding), you can remove the offending pixels in Firefox by setting overflow to hidden on the ul.

Hope this helps someone out there!

查看更多
在下西门庆
4楼-- · 2019-01-13 14:04

I've come across this problem in relation to text with transparent backgrounds.

I couldn't get any of the above solutions to work consistently so I ended up using a webkit hack to give those browsers a different line-height. Like so:

@media screen and (-webkit-min-device-pixel-ratio:0) {
    .your-class {
        line-height:20px;
    }
}

Eww, hacky! I try to avoid CSS hacks but I just couldn't find another way. I hope that helps someone.

查看更多
女痞
5楼-- · 2019-01-13 14:06

I had the same problem with my main tabs displaying them in Chrome, they were one pixel off in height and there for leaving an ugly slit between the tabs and the white background of the mainframe.

I solved the problem by giving the tab div an upper margin with a floated value. First tried margin-top:0.1px nothing then 0.2 etc. until with an upper margin of 0.5 everything displayed fine over all the major browsers.

查看更多
贪生不怕死
6楼-- · 2019-01-13 14:07

I guess this is the only way , use different styles for different browsers the problematic sections

/* FOR MOZILLA */
@-moz-document url-prefix() { 
.selector {
 color:lime;
}
}
/* FOR CHROME */
@media screen and (-webkit-min-device-pixel-ratio:0) { 
/* Safari and Chrome, if Chrome rule needed */
.container {
 margin-top:100px;
}
/* Safari 5+ ONLY */
::i-block-chrome, .container {
 margin-top:0px;
}``
查看更多
Fickle 薄情
7楼-- · 2019-01-13 14:08

I managed to solve this issue with a web font I was working with by setting the following:

.some-class {
    display: inline-table;
    vertical-align: middle;
}

Granted it's a bit hacky but does the job. It does mean though you will have target styles specifically for Internet Explorer

查看更多
登录 后发表回答