<分区>
我有一个名为 frontwidth 的 div id css,它包含 1 个 img 1 个标题和 1 个文本。
当我做第二个或第三个 frontwidth 时,它会放在自己后面,而不是在下面和下面。
最佳答案
根据我的评论:
Wow, that's.. a unique approach? You have far too much
position: absolute
andposition: 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
。除了 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/