IE6 边框底部:0 &填充 CSS 问题
我刚刚遇到了一个 IE6 错误,我似乎无法通过网络识别该错误。
基本上,这是触发行为的时候:块元素在除底部之外的所有侧面都有边框,以及顶部/底部填充。其中还有另一个块元素。
我的整个代码太大了,无法放在这里,但我将其范围缩小到这个简单的示例:
<div style="border: 5px solid red; border-bottom: 0; padding: 5px;">
<p>adasasasdas</p>
</div>
Following stuff
现在出错的是“以下内容”的位置(无论是什么)将被奇怪地改变。在本例中,左侧有几个像素。
要禁用这种奇怪的行为,我可以保留底部边框,去掉填充或使包含的元素内联。但我有点想要他们两个。在我不得不放弃它们之前,我想看看是否有关于这个错误的知识以及是否有替代修复方案。
谢谢!
I just encountered a IE6 bug that I don't seem to identify over the net.
Basically this is when the behavior is triggered: a block element has border, on all sides except bottom, and top/bottom padding. and inside it there's another block element.
My entire code is to big to fit in here, but I narrowed it down to this simple example:
<div style="border: 5px solid red; border-bottom: 0; padding: 5px;">
<p>adasasasdas</p>
</div>
Following stuff
Now the thing that goes wrong is that the "Following stuff"'s position (whatever that is), will be altered weirdly. In this case a few pixels to the left.
To disable that weird behavior I can either keep the bottom border, get rid of the padding or make the contained element inline. But I kinda want them both. Before I have to give them up, I wanted to see if there is knowledge about this bug and if there is an alternative fix.
Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
这是对错误的一个很好的修复:
基本上,IE6 的 div 末尾必须有一些内联文本才能正确呈现它。由于 在底部添加了额外的一行,因此我将
div
中的字体大小更改为 0,然后在< 内恢复为 16(或您通常使用的任何内容) ;p>
。这对 div 高度的影响非常小(在所有主要浏览器中大约为 2 像素),但用户根本不会注意到。或者,您可以尝试将div
中的line-height
变量更改为 0%,然后在p
中更改回 100%,但是这样当我尝试时,似乎比font-size
方法改变了div
的高度多几个像素。This is a pretty good fix to the bug:
Basically, there has to be some inline text at the end of the div for IE6 to render it correctly. Since the added an extra line to the bottom, I changed the font size to 0 in the
div
, then back to 16 (or whatever you'd normally use) inside the<p>
. This has a very minimal effect on the height of the div (about 2 pixels in all major browsers) but it shouldn't be at all noticeable to users. Alternatively, you can try altering theline-height
variable to 0% in thediv
, then back to 100% in thep
, but that seemed to change thediv
's height by a few more pixels than thefont-size
method when I tried it.我的解决办法是,
但这可能不适用于您,具体取决于上下文
My fix would be
but that may not be applicable for you depending on the context
这可能会帮助您
adasasasdas
以下内容
如果您想要填充,请调整
标记中的填充
This may help you
<div style="border-left: 5px solid red; border-top: 5px solid red; padding: 0px;">
<p style="margin:0px; padding:10px;">adasasasdas</p>
</div>
Following stuff
If you want padding adjust padding in
<p>
tag嘿,我知道这已经很旧了,但我也花了几个小时与这个错误作斗争(事实上,我花了很长时间才弄清楚这是因为 border-bottom + padding-bottom...这是一个耻辱因为如果我知道要搜索什么,我会更快找到这个)。
不管怎样,我突然想到这是ie6中hasLayout问题的另一种表现。出于我的目的,向有问题的 div 添加“zoom:1”会突然神奇地修复它,这样做的好处是不用担心字体大小和行高等。
Hey, I know this is old, but I also just spent several hours fighting with this bug (and in fact it took me this long to figure out that it was because of border-bottom + padding-bottom...which is a shame because if I knew what to search for I would've found this much sooner).
Anyway it suddenly occurred to me that this is yet another manifestation of the hasLayout issue in ie6. For my purposes, adding "zoom:1" to the offending divs suddenly and magically fixed it, which has the benefit of not fussing with font sizes and line heights and such.