Box div 不会扩展到 100% 宽度,而是扩展到内部 div 子级的宽度

发布于 2024-11-25 13:54:26 字数 1197 浏览 6 评论 0原文

我似乎只在 Firefox 3.0、Firefox 3.6 中出现以下 CSS 问题。使用较新版本的 Firefox(例如 3.6.6),我的布局工作正常。

在此处输入图像描述

不幸的是,我无法上传完整的屏幕截图。代码如下:

#header { width:100%; }
#header div.container { width:980px; margin:0 auto; }
#presentation { width:100%; background:red; }
#presentation div.bg { background-image:url(../images/img.png) no-repeat center top; }
#presentation div.container { width:980px; margin:0 auto; }

<div id="presentation">
<div class="bg">
<div class="container">
[content here]
</div><!-- end .container -->
</div><!-- end .bg -->
</div><!-- end #presentation -->

FF3.0 将 div.bg 中找到的背景图像剪切为 div.container 的宽度,尽管其父 div、#presentation 设置为 100%,并且只有其子 div 的宽度为 980px。 (没有逻辑原因为什么我的背景图像设置为 980px)

这似乎只在 FF 中。 Chrome、IE 等可以毫无问题地显示我的背景图像,并且不会剪切任何内容。

我尝试过: #presentation div、#presentation div.bg、overflow:hidden、html > 的 width:100%、height:100%、min-width、min-height #presentation,清除 #presentation 之后的 div 或其内部子元素。

到目前为止,我几乎可以在互联网上找到所有内容。

我的 HTML 文档主要使用 XHTML Strict 进行验证,除了一些我需要犯的错误(UL 内的 div) - 不在 #presentation div 内的错误。

I seem to have the following CSS issue only in Firefox 3.0, Firefox 3.6. With newer versions of Firefox, like 3.6.6 for example, my layout works fine.

enter image description here

Unfortunatelly, I can't upload a full screenshot. Here is the code:

#header { width:100%; }
#header div.container { width:980px; margin:0 auto; }
#presentation { width:100%; background:red; }
#presentation div.bg { background-image:url(../images/img.png) no-repeat center top; }
#presentation div.container { width:980px; margin:0 auto; }

<div id="presentation">
<div class="bg">
<div class="container">
[content here]
</div><!-- end .container -->
</div><!-- end .bg -->
</div><!-- end #presentation -->

FF3.0 cuts my background image found in div.bg to the width of div.container, altought its parent div, #presentation is set at 100% and only its children div has the width of 980px. (no logical reason why my background image is set to 980px)

This seems to be only in FF. Chrome, IE, etc. displays my background image with no problem and it doesn't cut anything.

I've tried: width:100%, height:100%, min-width, min-height to both the #presentation div, #presentation div.bg, overflow:hidden, html > #presentation, clearing div after #presentation or it's inner children.

Mostly everything I could find on the Internet so far.

My HTML document validates with XHTML Strict mostly, except a few errors that I'm required to make (a div inside a UL) - errors that aren't inside the #presentation div.

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

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

发布评论

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

评论(1

写给空气的情书 2024-12-02 13:54:26

我认为这可能是由于背景图像的重复,

顺便说一句,这应该是这样的:

#presentation div.bg { width: 980px; background:url("img.jpg") no-repeat top center; }

也许背景不够大,留下了一些空白空间?

根据您拥有的背景图像类型,您可能需要使用 repeat-x 而不是 no-repeat


顺便说一句.. 拥有宽度和宽度是一件好事具有 css 背景图像的 div 的高度属性,如果不是高度,则至少是宽度。在某些情况下,如果没有设置宽度,则使浏览器窗口小于包装器可能会导致背景图像被剪切,但这里不应该出现这种情况。

I think it might be due to the repeating of the bg image

this is what it should be like by the way:

#presentation div.bg { width: 980px; background:url("img.jpg") no-repeat top center; }

Maybe the background is not big enough and leaves some empty space?

Depending on what kinda of bg image you have, you might want to use repeat-x instead of no-repeat


By the way.. Its a good thing to have width and height attributes for the divs with css background images, or at least width if not heigh. In some cases making the browser window smaller than the wrapper may cause cutting of the background image if theres no set width though that shouldnt be the case here.

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