了解 CSS clear:both 的工作原理
我正在尝试整理一份基于 HTML 表单的调查问卷。当我遇到浮动元素问题时,我已经使用 CCS 排列了所有 HTML 表单元素。
我有一个包含一些表单元素的 DIV,我想将它们放置在前一个 DIV 下方。由于之前的 DIV“浮动”到左侧,我想我必须使用 CSS 语法 clear:both。然而,当我这样做时,我的内容一直跳到页面的左侧,跳出了它包含的 DIV。我不知道为什么。
我创建了一个 JSFiddle 示例来帮助解释...
任何人都可以看看我做错了什么以及为什么 clear:both 将我的 DIV 从所有容器中推出?谢谢。
I have an HTML form based questionnaire I am trying to put together. I had lined up all the HTML form elements using CCS when I came across a problem floating elements.
I have a DIV containing some form elements that I wanted to place underneath the previous DIV. Since the previous DIV was "floated" to the left I figured I had to use the CSS syntax clear:both. However, when I did that my content went all the way over to the left of the page jumping out of it's containing DIV. I am not sure why.
I have created a JSFiddle example to help explain ...
Can anyone see what I am doing wrong and why the clear:both is pushing my DIV out of all it's containers? Thank you.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这就是 CSS 清除的工作原理。
清除元素将位于任何先前的同级浮动元素下方。
您应该使用众多 cleafix 方法之一。
这是 html5boilerplate 中的一个:
这是代码上的样子:http://jsfiddle.net/BrWUE/1/ 。
This is how CSS clearing is supposed to work.
The clearing element will go underneath any prior sibling floated elements.
You should use one the numerous cleafix methods out there.
Here's one from the html5boilerplate:
And here's what it looks like on your code: http://jsfiddle.net/BrWUE/1/ .