Firefox 浮动
    ...额外的顶部填充或边距,即使在默认重置后也是如此?

发布于 2024-08-13 19:03:11 字数 1727 浏览 5 评论 0原文

我有一个简单的浮动水平列表,在 IE 和 Opera 中看起来不错,但 Firefox 在顶部有额外的填充或边距,我不知道如何修复。它看起来很好,直到我不得不添加一个显示:由于另一个问题,内联到旁边的图像链接,所以我认为这与显示属性有关..有什么想法吗?在过去的八个小时里我一直在试图解决这个问题。

#header {
 background: url(../Images/header_bkg.png) repeat-x;
 width: 800px;
 height: 125px;
 position: relative;
}
#header ul {
 list-style-type: none;
 margin: 0;
 padding: 0;
 float: right;
}
#header li {
 float: left;
 padding: 0 6px 0 0;
 margin: 0;
}
#header a, #header a:visited {
 font-family: Verdana, Arial, Helvetica, sans-serif;
 font-size: .7em;
 color: #333333;
 text-decoration: none;
 padding: 2px;
 display: block;
}
#header a:hover {
 font-size: .7em;
 color: #FFFFFF;
 background: #DCAD33;
 text-decoration: none;
 display: block;
}

<div id="header">
<img src="../Images/right_header_bar.png" style="float:right" />
<a href="../index.html" style="background:none; display: inline"><img src="../Images/Scofield_logo.png" style="float:left; padding: 0 0 0 20px" /></a>
<ul>
<li><a href="../index.html">HOME</a></li>
<li><a href="../Portfolio/portfolio.aspx">PORTFOLIO</a></li>
<li><a href="../Unique/ShipReady.aspx">RARITIES</a></li>
<li><a href="../custom.html">CUSTOM</a></li>
<li><a href="../trade.html">TRADE</a></li>
<li><a href="../Company.html">COMPANY</a></li>
<li><a href="../press.html">PRESS</a></li>
<li><a href="http://scofieldhistoriclighting.blogspot.com/" target="_blank">BLOG</a></li>
<li><a href="../Contact.html">CONTACT</a></li>
</ul>
</div>

I've got a simple floated horizontal list that is looking good in IE and Opera, but Firefox has extra padding or margin at the top that I don't know how to fix.. It looked fine until I had to add a display:inline to an image link next to it because of another issue, so I think it's something to do with the display attribute.. any ideas? I've been trying to figure this out for the past eight hours.

#header {
 background: url(../Images/header_bkg.png) repeat-x;
 width: 800px;
 height: 125px;
 position: relative;
}
#header ul {
 list-style-type: none;
 margin: 0;
 padding: 0;
 float: right;
}
#header li {
 float: left;
 padding: 0 6px 0 0;
 margin: 0;
}
#header a, #header a:visited {
 font-family: Verdana, Arial, Helvetica, sans-serif;
 font-size: .7em;
 color: #333333;
 text-decoration: none;
 padding: 2px;
 display: block;
}
#header a:hover {
 font-size: .7em;
 color: #FFFFFF;
 background: #DCAD33;
 text-decoration: none;
 display: block;
}

<div id="header">
<img src="../Images/right_header_bar.png" style="float:right" />
<a href="../index.html" style="background:none; display: inline"><img src="../Images/Scofield_logo.png" style="float:left; padding: 0 0 0 20px" /></a>
<ul>
<li><a href="../index.html">HOME</a></li>
<li><a href="../Portfolio/portfolio.aspx">PORTFOLIO</a></li>
<li><a href="../Unique/ShipReady.aspx">RARITIES</a></li>
<li><a href="../custom.html">CUSTOM</a></li>
<li><a href="../trade.html">TRADE</a></li>
<li><a href="../Company.html">COMPANY</a></li>
<li><a href="../press.html">PRESS</a></li>
<li><a href="http://scofieldhistoriclighting.blogspot.com/" target="_blank">BLOG</a></li>
<li><a href="../Contact.html">CONTACT</a></li>
</ul>
</div>

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

红尘作伴 2024-08-20 19:03:12

我通过清除浮动并添加不间断空格解决了这个问题...

首先,在 CSS 文件中,我使用以下方法创建了

#clear_floats {clear:both;}

然后,在我的代码中,就在我的新代码之前浮动元素:

<div id="clear_floats"> </div>

为我工作。希望这有帮助。

I fixed this problem by clearing floats and adding a non-breaking space...

first, in CSS file, I created <br /> using:

#clear_floats {clear:both;}

Then, in my code, just before my new floated elements:

<div id="clear_floats"> </div>

Worked for me. Hope this helps.

吹泡泡o 2024-08-20 19:03:12

鉴于上面的代码,我没有看到它。更完整的测试用例?

一般来说,当您混合浮动内容和内联流内容时,您必须将右浮动内容放在流内容之前,否则它往往会跳到您当前正在写入的文本行下方的下一个文本行。不过,这对 IE 的影响比对 Firefox 的影响更严重。

I don't see it, given the code above. More complete test case?

In general, when you are mixing floated content and inline flow content, you have to put the right-floated content before the flow content or it tends to jump down to the next text line below the one you're currently writing on. This affects IE worse than it does Firefox though.

青萝楚歌 2024-08-20 19:03:12

解决了我遇到的问题,也许可以解决你的问题。我的右侧浮动在顶部有额外的空间,即使两个并排的 div 具有相同的 h1 标签。为了解决这个问题,我简单地向浮动中的 h1 添加了零顶部填充和零顶部边距,从而使其在顶部与左侧非浮动的 h1 同等地齐平。

也许在 UL 或 LI 中添加一些零填充和边距可以解决您的问题。

Solved the problem I was having, it may fix yours. My right float had the extra space at the top even though both side by side divs had the same h1 tag. To solve it I simply added zero top padding and zero top margin to the h1 that was in the float, thus making it equally flushed at top with the h1 on the left non floated.

Perhaps adding some zero padding and margin to your UL or LI's will solve yours.

风铃鹿 2024-08-20 19:03:12

我必须进行两项更改才能使所有这些浏览器看起来相等:

body
{
    margin: 8px;
}

这使得浏览器边距对齐,每个浏览器都有自己的默认边距,您应该在开始编码之前先行重置该边距,因为我没有其余的代码可能是问题所在。

另外,代替 display: inline

 <a href="../index.html" style="background: none; float: left">

I had to make two changes to get all those browsers to look equal:

body
{
    margin: 8px;
}

This made the browsers margin to align, each browser has its own default margin that you preemptively should reset before starting your coding, since I dont have the rest of your code this could be the issue.

Also, instead of the display: inline

 <a href="../index.html" style="background: none; float: left">
月下伊人醉 2024-08-20 19:03:12

我认为他没有遇到过这种情况。发现这个帖子有类似的问题。

例如,如果您采用 float:right 并将其放置在下一个 div 之上,理论上它们应该并排。现在向这两个 div 添加 h1 标签或其他内容,您将看到在 Firefox 中 float:right div 将在其上方具有双填充或额外填充。即使您将边距和填充设置为零,这种情况也存在。

例如,

< div style="float:right:margin:0;padding:0;width:280px;">
< h1>Head Right< / h1>
< /div>

< div style="margin:0;padding:0;width:300;">
< h1>Head Left< /h1>
< /div>

奇怪的是,您可以在不浮动的 div 周围添加边框(左我的示例)并将其设置为 1px 纯白色,这样它在视觉上不可见,并且它将消除额外的空间....我不明白为什么它那里。我什至尝试向左侧非浮动 div 添加宽度,但仍然有空间。

I dont think that is what he has encountered. Found this post with a similar issue.

if you take a float:right for example and place it above the next div in theory they should be side by side. Now add a h1 tag or something to both of those divs and you will see that in firefox the float:right div will have double padding or extra padding above it. This exists even if you place margins and paddings at zero.

e.g.

< div style="float:right:margin:0;padding:0;width:280px;">
< h1>Head Right< / h1>
< /div>

< div style="margin:0;padding:0;width:300;">
< h1>Head Left< /h1>
< /div>

what odd is that you can add a border around the div thats not floated (left my example) and set it to 1px solid white so its not visually visable and it will negate that extra space.... I cant figure out why its there. I even tried adding a width to the left non floated div and still got the space.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文