CSS绝对位置元素延伸背景
我有一个绝对位置 div,它与容器背景重叠,因为它具有较大的高度。该 div 与位于其左侧的 body div 共享容器。
有没有办法将容器扩展到绝对定位的 div 的高度,而不是主体内容的高度?
或者我应该并排浮动 div 并在两者的底部放置一个 ?似乎是一个让容器扩展的混乱黑客:/
编辑:评论似乎不喜欢代码结构。所以我也将其编辑到这里。
布局是:
<div id="content">
<div class="container">
<div id="header"></div>
<div id="main">
<div id="column-1"></div>
<div id="column-2"></div>
</div>
</div>
</div>
#content
有重复的背景,#container设置页面的固定宽度。 #header
存放链接,#main
存放包含页面主要内容的两列。我无法让这两列彼此相邻(浮动/绝对),同时让 #content's
背景在它们下方重复
I have a absolutely position div that is overlapping a containers background due to it having a larger height. This div is sharing the container with a body div that's sitting happily to the left of it.
Is there a way to extend the container to be the height of the absolutely positioned div, rather than the body content?
Or should I just float the divs side by side and chuck a <div style="clear: both"></div>
at the bottom of the two? Seems like a messy hack to get a container to extend :/
EDIT: Comments don't seem to like code structure. So I'll edit it into here as well.
The layout is:
<div id="content">
<div class="container">
<div id="header"></div>
<div id="main">
<div id="column-1"></div>
<div id="column-2"></div>
</div>
</div>
</div>
#content
has a repeated background and #container sets the fixed width of the page. #header
sits up to for the links and #main
holds the two columns which have the main content for the page. I can't get those two columns to sit next to each other (float / absolutely) whilst having the #content's
background repeat down below them
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
使用此布局:
您的基本 CSS 应该类似于:
您说您希望背景图像出现在内容下方。由此我假设您的意思是您希望页面为全屏高度(最小值)。
绝对定位的要点在于,它从正常流中删除了元素,因此您不能让它的“容器”扩展以包含它,因为从技术上讲它没有容器。
绝对定位有其一席之地,但十分之九的情况是我使用基于浮动的布局获得了更好的结果。但如果没有更多信息,我真的无法说更多。
With this layout:
your basic CSS should be something like:
You said you wanted the background image appearing below the content. From this I assume you mean you want the page to be full screen height (minimum).
The point of absolute positioning is that it removes the element from the normal flow so no you can't have it's "container" extend to include it because technically it has no container.
Absolute positioning has its place but 9 times out of 10 I get better results with a float-based layout. But I can't really say more without more information.