简体   繁体   English

Firefox和Chrome渲染div高度不同

[英]Firefox and Chrome rendering div height differently

First, thanks for checking out my question. 首先,感谢您查看我的问题。 My problem is i'm trying to create a fixed menu at the top of a site, but when i use div elements for the different menu items (to achieve the visual effect i'd like) chrome seems to render the div elements with extra padding at the top, differently than firefox. 我的问题是我正在尝试在网站顶部创建一个固定菜单,但是当我使用div元素用于不同的菜单项(以实现我喜欢的视觉效果)时,chrome似乎会使用额外的div元素在顶部填充,与firefox不同。 I've included the code, along with a jsfiddle to show the difference. 我已经包含了代码,还有一个jsfiddle来显示差异。 Any help on how to achieve the desired effect (which is closer to the firefox rendering that the one in chrome as I'm sure you could guess) would be incredibly helpful. 任何关于如何实现所需效果的帮助(更接近火影渲染,我确信你能猜到的那个渲染)会非常有用。 I'd like the hover color of the menu items to reach the bottom of the fixed black bar, with the text equidistant top to bottom. 我希望菜单项的悬停颜色到达固定黑条的底部,文本从上到下等距离。 Thank you for your time! 感谢您的时间!

EDIT: see below conversation, this is the desired look im going for (rendering correctly in chrome) http://jsfiddle.net/9wQxu/5/ 编辑:见下面的对话,这是我想要的外观(在chrome中正确呈现) http://jsfiddle.net/9wQxu/5/

The code as follows: (apologies for poor formatting) 代码如下:(对格式不佳道歉)

HTML: HTML:

<div id="topbar">
<div class="facebook">
<a href="http://www.facebook.com/pages/Kristen-Hemphill/359919877367564">
<img src="img/facebook_logo.png" style="width:28px; height:28px; padding-left:5px; padding-top:2px; float:left;" />
</a>
<a href="http://twitter.com/krishemp">
<img src="img/twitter.png" style="width:28px; height:28px; padding-left:5px; padding-top:2px; float:left;" />
</a>
        </div>
        <div class='menuitem'>  <a href="index.php">HOME</a>
        </div>
        <div class='menuitem'>  <a href="media.html">LISTEN</a>
        </div>
        <div class='menuitem'>  <a href="gallery.html">GALLERY</a>
        </div>
        <div class='menuitem'>  <a href="bio.html">BIO</a>
        </div>
        <div class='menuitem'>  <a href="calendar.html">CALENDAR</a>
        </div>
        <div class='menuitem'>  <a href="booking.html">BOOKING</a>
        </div>
    </div>

CSS: CSS:

@import url(http://fonts.googleapis.com/css?family=Josefin+Sans:400);

a:link {color:#000;text-decoration:none; font-family: 'Josefin Sans', sans-serif;}     /* unvisited link */
a:visited {color:#000;text-decoration:none;font-family: 'Josefin Sans', sans-serif;}  /* visited link */
a:hover {color:#36d8e7;text-decoration:none;font-family: 'Josefin Sans', sans-serif;}  /* mouse over link */
a:active {color:#36d8e7;text-decoration:none;font-family: 'Josefin Sans', sans-serif;}  /* selected link */

.menuitem a{width:auto;
    font-size:30px;
    z-index:9999; 
    float:left; 
    padding: 0px 10px 0px 10px;
    color: #fff;
    background-color: #000;   
}

.menuitem a:hover {
    color: #fff;
    background-color: #36d8e7;
    }

#topbar {
    background-color:#000;
    position:fixed;
    z-index:999;
    width:100%;
    height:40px;
    color:#fff;
    top:0;
    left:0;
    }

.facebook {
    top:0px; 
    position:relative; 
    float:left;
    }

Add line-height: 30px; 添加line-height: 30px; to .menuitem in CSS. 到CSS中的.menuitem。

Edit I've tried with this CSS: 编辑我试过这个CSS:

.menuitem a {
        width:auto;
        font-size:30px;
        line-height:100%;
        z-index:9999; 
        float:left;
        padding: 5px 10px 5px 10px;
        color: #fff;
        background-color: #000;   
}

and it should work - but I've got almost 100% same result only when Google font is commented out and Arial is used. 它应该工作 - 但只有当Google字体被注释掉并使用Arial时,我才能得到几乎100%相同的结果。 So it's obviously a difference in the font-rendering itself. 所以这显然是字体渲染本身的一个区别。 I'm also always going crazy becuase of such differences ;) 我也总是疯狂,因为这种差异;)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM