div定位的问题

发布于 2024-09-08 18:56:26 字数 442 浏览 0 评论 0原文

A 有类似的东西: 替代文本 http://img718.imageshack.us/img718/9625/88827634.png< /a>

没关系,但我想在内容顶部添加一些标题块。

所以它可以看起来像这样: 替代文本 http://img824.imageshack.us/img824/9541/31597153.png< /a>

我不知道标题高度是多少,因为会有一些动态内容。

如何解决这个问题呢?

A have something like that:
alt text http://img718.imageshack.us/img718/9625/88827634.png

It's OK but i want to add some Title block at the top of Content.

So it can be look like that:
alt text http://img824.imageshack.us/img824/9541/31597153.png

I don't know what Title height will be, because there will be some dynamic content.

How to solve this problem?

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

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

发布评论

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

评论(1

倒带 2024-09-15 18:56:26

为什么你把所有的div都放在绝对位置?

无论如何,您可以用 2 个 div 包裹标题和内容,外部 div 必须是绝对的,内部 div 是相对的,并且您可以在标题和内容

<div style="position:absolute">
  <div style="position:relative">
      <div style="position:absolute">Title</div>
      <div style="position:absolute">Content</div>
  </div>
</div>

图中将绝对定位放在标题和内容的顶部和左侧,因为它不会超出你绘图的绿色和蓝色。

我将最外面的 div 绝对定位,因为你将所有 div 都绝对定位。我假设您已经有了所有尺寸,就像您的第一张图中一样。

why are you positioning all your divs in absolute?

anyways you can wrap Title and Content with 2 divs, the outer div must be in absolute and the inner div is a relative, and you can put an absolute positioning in your Title and Content

<div style="position:absolute">
  <div style="position:relative">
      <div style="position:absolute">Title</div>
      <div style="position:absolute">Content</div>
  </div>
</div>

Figure out the Top and Left of Title and Content, since it will not go outside the green and blue colors of your drawing..

I position absolute the outermost div since you are positioning all your divs in absolute. I assume you already have the measurements for all just like in your first drawing.

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