CSS 布局问题、浮动、嵌套 div

发布于 2024-08-21 03:20:05 字数 413 浏览 3 评论 0原文

好吧,我已经在我正在开发的这个个人网站上收到了一些有用的信息。在我混乱的嵌套 div 中的某个地方,我给自己制造了一些问题。我将该图像及其旁边的文本都浮动在另一个 div 中,并将该 div 居中,这很好。但为了在其下方开始一个新段落,我必须将该段落放在 div 中,因为需要清除其上方的浮动(或者它在 div 旁边的右边距中显示文本)。我确信有一种更简单的方法可以做我想做的事情。如果有人能够看一下我的代码并看看我在结构上哪里出了问题,那将是一个很大的帮助......非常感谢。

正如您所看到的,显示“最近的工作”的标题像预期的那样居中,但没有为其上方的框提供通常的边距。

这是链接:

http://danberinger.com/

Alright, I have received some helpful information on this personal site I am working on already. Somewhere in my jumbled mess of nested divs I have created some problems for myself. I have floated both that image and the text next to it inside another div and centered that div, which is fine. But in order to start a new paragraph below it, I must put that paragraph within a div because the floats above it need to be cleared(or it displays the text in that right margin next to the div). I am sure there is an easier way of doing what I want to do. If someone might be able to take a look at my code and see where I am going wrong structure wise it would be a great help...thanks a lot.

As you can see, there heading that says "Recent Work" is being centered like it is supposed to but it is not being given the usually margin from that box above it.

Here is the link:

http://danberinger.com/

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

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

发布评论

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

评论(3

笑脸一如从前 2024-08-28 03:20:05

overflow:hidden; 放入第 110 行的 div#intro_container 选择器中,

以了解其工作原理,请阅读以下内容:http://csswizardry.com/floats/

put overflow:hidden; into the div#intro_container selector on line 110

to understand why it works read this here: http://csswizardry.com/floats/

怕倦 2024-08-28 03:20:05

问题是 intro_container 没有获取其子级的完整高度。通过在浮动的 2 个 div 之后放置一个设置了清晰样式的元素,您将获得所需的效果:

<div id="intro_container">

  <div id="messagebox">
    ...
  </div>

  <div id="picture">
    ...
  </div>

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

这将为“最近的工作”提供正常的填充。

The problem is that intro_container does not take the full height of its children. You will get the desired effect by putting an element with the clear style set after the 2 divs you are floating:

<div id="intro_container">

  <div id="messagebox">
    ...
  </div>

  <div id="picture">
    ...
  </div>

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

This will give "Recent Work" the normal padding.

寂寞清仓 2024-08-28 03:20:05

我认为 CSS clearfix 将完全按照您所描述的方式进行操作,而无需使用额外的 div 元素来污染您的代码。 http://www.webtoolkit.info/css-clearfix.html 只需添加CSS 样式和 .clearfix 类适用于从浮动子项折叠的任何 div。

I think CSS clearfix will do exactly what you are describing without needing to taint your code with extra div elements. http://www.webtoolkit.info/css-clearfix.html Just add the CSS styles and the .clearfix class to any divs which are collapsing from floating children.

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