Div 浮动 & 负边际

发布于 2024-07-29 02:54:56 字数 871 浏览 3 评论 0原文

我希望这是一个简单的,但我似乎无法快速破解它......

我有一个 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 技术交流群。

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

发布评论

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

评论(3

染墨丶若流云 2024-08-05 02:54:57

干得好:

<div id="container" style="position: relative;">
  <div id="col_1" style="float:left; padding-bottom:200px; background-color: #235124;">Some static content<br />Another line</div>
  <div id="col_2" style="float:left">AJAX content</div>

  <div style="clear:left"></div>

  <div id="flash_container" style="margin-top: -200px; position: absolute;">
    <object>
      <param name="movie" value="boxheadrooms.swf">
      <embed src="boxheadrooms.swf" width="550" height="400">
      </embed>
    </object>
  </div>
</div>

需要一个额外的 div 将其全部包裹起来,但需要启用相对定位。

忽略我添加的额外标签、Flash 对象和背景颜色,它们只是为了让我在尝试了解发生的情况时更清楚地了解问题。

Here you go:

<div id="container" style="position: relative;">
  <div id="col_1" style="float:left; padding-bottom:200px; background-color: #235124;">Some static content<br />Another line</div>
  <div id="col_2" style="float:left">AJAX content</div>

  <div style="clear:left"></div>

  <div id="flash_container" style="margin-top: -200px; position: absolute;">
    <object>
      <param name="movie" value="boxheadrooms.swf">
      <embed src="boxheadrooms.swf" width="550" height="400">
      </embed>
    </object>
  </div>
</div>

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.

巴黎盛开的樱花 2024-08-05 02:54:57

是的你可以。 负边距会将您的 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.

南烟 2024-08-05 02:54:57

将两列包裹在一个 div 中,并使用 overflow:hidden 清除浮动。 使用 clear:bothposition:relative 使 Flash div 向左移动并覆盖两列。

我添加了背景颜色和高度,这样我就可以看到 div 的放置位置。

   <div id="container">
        <div style="overflow:hidden;">
            <div id="col_1" style="float:left; padding-bottom:200px;background-color:#c00;">Some static content</div>
            <div id="col_2" style="float:left;height:300px;background-color:#0c0;">AJAX content</div>
        </div>

        <div id="flash_container" style="margin-top:-200px;position:relative;clear:both;background-color:#ccc;height:100px;">
            <object>Flash file</object>
        </div>
    </div>

Wrap the two columns in a div and use overflow:hidden to clear the float. Use clear:both and position: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.

   <div id="container">
        <div style="overflow:hidden;">
            <div id="col_1" style="float:left; padding-bottom:200px;background-color:#c00;">Some static content</div>
            <div id="col_2" style="float:left;height:300px;background-color:#0c0;">AJAX content</div>
        </div>

        <div id="flash_container" style="margin-top:-200px;position:relative;clear:both;background-color:#ccc;height:100px;">
            <object>Flash file</object>
        </div>
    </div>
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文