Div 浮动 & 负边际
我希望这是一个简单的,但我似乎无法快速破解它......
我有一个 2 列布局,右列中的内容是动态的和 ajax 驱动的。 因此,页面高度会根据右列中的内容而变化。
我想将一个小的 Flash 文件 (400px x 200px) 固定在页面底部,但位于第 1 列下方。
这很简单。 问题是..我希望闪光灯有一个负的上边距-200px,这样它就不会自己被卡住。 这也减少了浪费的空白空间。
<div id="container">
<div id="col_1" style="float:left; padding-bottom:200px;">Some static content</div>
<div id="col_2" style="float:left">AJAX content</div>
<div style="clear:left"></div>
<div id="flash_container" style="margin-top:-200px;>
<object>Flash file</object>
</div>
</div>
我已经大大简化了代码,但是您应该明白我的意思。 简单的 2 列,清除列,在 Flash div 上塞上负边距。 在 IE6、Safari 中工作正常,在 Opera、Firefox 和 Chrome 中则严重失败。
您可以“通过”透明应用负边距吗?
感谢所有帮助;)
I hope this is a simple one, but I can't seem to be able to crack it quickly...
I've got a 2 column layout, with the content in the right column being dynamic and ajax driven. So the page height changes depending on what is in the right column.
I want to have a small flash file (400px x 200px) bolted on to the bottom of the page, but underneath column 1.
That's easy. The problem is.. I want the flash to have a negative top margin of -200px, so it doesn't get stuck out all on it's own. This also reduces the wasted white space.
<div id="container">
<div id="col_1" style="float:left; padding-bottom:200px;">Some static content</div>
<div id="col_2" style="float:left">AJAX content</div>
<div style="clear:left"></div>
<div id="flash_container" style="margin-top:-200px;>
<object>Flash file</object>
</div>
</div>
I've simplified the code quite a lot, but you should see what i mean. Simple 2 columns, clear the columns, bung a negative margin on the flash div. Works fine in IE6, Safari, Fails miserably in Opera, Firefox and Chrome.
Can you apply a negative margin "through" a clear?
All help appreciated ;)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
干得好:
需要一个额外的 div 将其全部包裹起来,但需要启用相对定位。
忽略我添加的额外标签、Flash 对象和背景颜色,它们只是为了让我在尝试了解发生的情况时更清楚地了解问题。
Here you go:
Requires an extra div to wrap it all in but it is required to enable the relative positioning.
Ignore the extra tags, flash objects and background colours I added, they were just to make the problem clearer to me when I was trying to understand what was happening.
是的你可以。 负边距会将您的 Flash 容器 div 放在那里。 问题是,它的内容应该如何表现。
我猜想,如果您用长文本替换 Flash 对象,您会看到文本在“向上”开始时仍然环绕浮动。
尝试用 margin-bottom 替换 padding-bottom 或更改 Flash 对象元素的显示属性。
Yes, you can. Negative margin will put your flash container div up there. The question is, how its content should behave.
I guess that if you replace your flash object with long text, you will see that the text, while starting "up there", still wraps around the floats.
Try replacing padding-bottom with margin-bottom or changing the display property of your flash object element.
将两列包裹在一个 div 中,并使用
overflow:hidden
清除浮动。 使用clear:both
和position:relative
使 Flash div 向左移动并覆盖两列。我添加了背景颜色和高度,这样我就可以看到 div 的放置位置。
Wrap the two columns in a div and use
overflow:hidden
to clear the float. Useclear:both
andposition:relative
to get the flash div to move to the left and overlay the two columns.I added the background colors and heights so I could see where the divs are placed.