CSS 布局问题、浮动、嵌套 div
好吧,我已经在我正在开发的这个个人网站上收到了一些有用的信息。在我混乱的嵌套 div 中的某个地方,我给自己制造了一些问题。我将该图像及其旁边的文本都浮动在另一个 div 中,并将该 div 居中,这很好。但为了在其下方开始一个新段落,我必须将该段落放在 div 中,因为需要清除其上方的浮动(或者它在 div 旁边的右边距中显示文本)。我确信有一种更简单的方法可以做我想做的事情。如果有人能够看一下我的代码并看看我在结构上哪里出了问题,那将是一个很大的帮助......非常感谢。
正如您所看到的,显示“最近的工作”的标题像预期的那样居中,但没有为其上方的框提供通常的边距。
这是链接:
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:
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
将
overflow:hidden;
放入第 110 行的div#intro_container
选择器中,以了解其工作原理,请阅读以下内容:http://csswizardry.com/floats/
put
overflow:hidden;
into thediv#intro_container
selector on line 110to understand why it works read this here: http://csswizardry.com/floats/
问题是
intro_container
没有获取其子级的完整高度。通过在浮动的 2 个 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:This will give "Recent Work" the normal padding.
我认为 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.