简体   繁体   English

浮动/背景色/填充ie6错误

[英]float / background-color / padding ie6 bug

I'm having a problem with my website. 我的网站有问题。 The following code isn't displayed correctly in ie6. 以下代码在ie6中无法正确显示。 The left padding is missing. 左填充丢失。

<div style="width: 600px; margin: 0 auto; padding: 0 32px; border: 1px solid red;">
  <div style="margin: 0 auto 48px; padding: 16px; border: 1px solid #404050; background-color: #a0a0a0;">
   <div style="float: right;">top_right</div>
   <div style="clear: both;"></div>
   <div>test</div>
  </div>
</div>

I changed all the styling to inline for the sake of the example. 为了示例,我将所有样式都更改为内联。 I do not want to simply set the text-align to right for the "top_right" text, because I have some other strange random errors like this. 我不想简单地将“ top_right”文本的text-align设置为right,因为我还有其他一些奇怪的随机错误,例如这样。 Also, if I remove the background-color, it works fine (in this case). 另外,如果我删除了背景色,则效果很好(在这种情况下)。

What should I do? 我该怎么办? All help will be appreciated, thanks! 所有帮助将不胜感激,谢谢!

ie6 width value must be a fix. ie6宽度值必须是一个固定值。

<div style="width: 600px; margin: 0 auto; padding: 0 32px; border: 1px solid red;">
   <div style="margin: 0 0 48px; width:566px; padding:16px; border: 1px solid #404050; background-color: #a0a0a0;">
      <div style="float: right;">top_right</div>
      <div style="clear:both">test</div>
   </div>
</div>

The first thing to try when fighting with IE6 is to set hasLayout . 与IE6对抗时,要尝试的第一件事是设置hasLayout Use zoom: 1 for the second <div> . 对第二个<div>使用zoom: 1

One solution could be make it absolute positioning, and then set the distance from the right side to be the same as the padding. 一种解决方案是使其绝对定位,然后将距右侧的距离设置为与填充相同。 Only problem with this is the text on the left will be on the same line, so you would have to have some sort of spacer there if you need it to be on its own line. 唯一的问题是,左侧的文本将在同一行上,因此,如果需要将其放在单独的行上,则必须在其中有某种分隔符。

<div style="width: 600px; margin: 0 auto; padding: 0 32px; border: 1px solid red;">
   <div style="position:relative; margin: 0 auto 48px; padding: 16px; border: 1px solid #404050; background-color: #a0a0a0;">
      <div style="position:absolute; right:16px;">top_right</div>
      <div style="clear: both;"></div>
      <div>test</div>
   </div>
</div>

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

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