html - Div 定位的问题

标签 html css

<分区>


想改进这个问题吗? 更新问题,使其只关注一个问题 editing this post .

关闭 3 年前

我有一个名为 frontwidth 的 div id css,它包含 1 个 img 1 个标题和 1 个文本。

当我做第二个或第三个 frontwidth 时,它会放在自己后面,而不是在下面和下面。

最佳答案

根据我的评论:

Wow, that's.. a unique approach? You have far too much position: absolute and position: relative. I just fixed this in Firebug, but it's going to take a few minutes to write an answer, the amount of rules I had to toggle and add.

从每个元素中删除 position 规则:

  • #mainbody.
  • #frontwidth
  • #titlesbig
  • #greyline
  • #homepageimage
  • #titlesmedium
  • #homepagetext
  • 希望我没有忘记任何东西:D

除了 mainbody 之外,您将多次使用这些元素中的每一个。

因此,改为使用

例如,在您的 HTML 中,更改为:

<div class="frontwidth">

然后在您的 CSS 中,更改为:

.frontwidth {

}

现在我们可以根据需要对这些元素进行布局了:

  • .homepageimage 上,添加 float: left
  • .frontwidth 上,添加 overflow: hidden(到 clear the floats)。
  • .titlesmedium.homepagetext 上添加 margin-left: 340px

关于html - Div 定位的问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5378174/

上一篇:html - Internet Explorer、z-index 和 "modality"

下一篇:html - 如何使用 javascript 将图像添加到工具提示?

相关文章:

html - 使标题 div 位于顶层

jquery - 获取隐藏图像的高度

html - 如何在文本区域中重新定位调整大小指示器

php - 如何设置下拉列表的样式?

jquery - HTML5 输入类型数字在 "9"之后出现奇怪的行为

javascript - 不使用 GET 将值传递到 iframe

html - 拆分宽度 : 100% parent container into sections with decimals? 的最佳方法是什么

css - 流体宽度如何工作?

html - 在 phpstorm 中设置背景 css 图像 - "cannot resolve file"

javascript - PHP 输出未出现在 HTML 中