简体   繁体   English

CSS'clear:both;“不适用于IE7浏览器。IE8/ IE9,Firefox,Chrome等都没有问题

[英]CSS 'clear:both;" not working as expected for IE7 browsers. No problems in IE8/IE9, Firefox, Chrome, etc

I've received several complaints from visitors to one of my websites. 我收到了我网站之一访问者的几项投诉。 Individuals contacting us regarding these issues are using IE7, running on Windows XP. 就这些问题与我们联系的个人正在使用Windows XP上运行的IE7。 I can replicate the issue either by running IE7 itself, or by displaying the site in IE8/IE9 in compatibility mode, with IE7 document mode selected. 我可以通过运行IE7本身或通过以兼容模式在IE8 / IE9中显示站点并选择IE7文档模式来复制该问题。

This page contains a registration form with fieldwraps that float:left, and occasionally are assigned a "clear:both" to start a new line of fields. 该页面包含一个带有float:left的换行符的注册表格 ,有时会分配一个“ clear:both”以开始新的一行行。 Again, the desired output can be viewed in any modern, standards compliant browser, or even in IE8/IE9. 同样,可以在任何符合标准的现代浏览器中甚至在IE8 / IE9中查看所需的输出。

If you need any clarification of the problem, I'm happy to provide it, and greatly appreciate any assistance you can offer! 如果您需要任何问题的说明,我们很乐意提供,非常感谢您可以提供的任何帮助!

You are mixing floats and clears in a bad way. 您正在以错误的方式混合浮动和清除。 There are the DIVs with the labels and the fields and you just need to float these divs, but you are also floating the fields and labels inside the DIVs without clearing them. 有带有标签和字段的DIV,您只需要浮动这些div,但是您也可以在DIV中浮动字段和标签而不清除它们。 This is a Problem in IE7. 这是IE7中的问题。

The Clear: both needs to be on a separate div after the two elements you want to clear. 清除:两个都需要放在要清除的两个元素之后的单独的div上。 Failing that you can wrap the fields you want to clear in a clear fix using the :after pseudo element. 否则,您可以使用:after伪元素将要清除的字段包装在一个明确的修订中。

See this thread: What methods of 'clearfix' can I use? 看到这个线程: 我可以使用'clearfix'的哪些方法?

Also sometimes with IE7 if you don't force haslayout it can mess around with your floats. 有时也使用IE7,如果不强制使用haslayout,它可能会与您的浮动对象混在一起。 The easiest way to do this is to add zoom:1; 最简单的方法是添加zoom:1; to your ie7 stylesheet. 到您的ie7样式表。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM