ie 中的像素间隙

发布于 2024-08-07 12:26:25 字数 1409 浏览 6 评论 0原文

我使用 absolute 定位放置了四个 Div,每个 Div 都是它们组合在一起后形成的矩形的边框,以便看起来像是选择了页面上的 Dom 元素(这模仿了 css使用 Div 作为覆盖层的边框行为)。

  • 左边的左边框设置为“4px 纯红色”宽度为 0px,高度等于边框的高度选定的 Dom 元素

  • 顶部的边框顶部设置为“4px 纯红色”,高度为 0px,宽度等于所选 Dom 元素的宽度。

等等你可以看到这是怎么回事。

我知道这很奇怪,但它非常有用,请参阅 aardvark 示例。

下面是它在 FF、opera、safari 和 chrome 中的样子:

alt text http: //img243.imageshack.us/img243/429/captureyv.png

这是它在 ie 8 中的样子:

alt text http://img190.imageshack.us/img190/7196/capture1dv.png

我立即想到了盒子模型问题,但是不是应该让它变窄吗?无论如何,我使用 jquery 来获取宽度和高度,这应该可以防止此类问题。我遇到了 最知名的 ie bug ,但找不到匹配项。

你怎么认为 ?

PS:这是一个书签,当然我尝试更改本地文件上的文档类型并且它有效,但在生产中我将无法这样做。

我使用 ie 开发工具栏在绝对定位的元素周围绘制边框:

alt text http: //img21.imageshack.us/img21/3425/capture2uc.png

我们可以看到差距。

I have four Div placed using absolute positioning, each of them is a border of a rectangle they form once grouped together, in order to look like if a Dom element on the page is selected (this mimic the css border behavior using Div as overlays).

  • The left one has a border left set to "4px solid red", a width of 0px and a height equal to the the height of the selected Dom element.

  • The top one has a border top set to "4px solid red", a height of 0px and a width equal to the the width of the selected Dom element.

etc. you can see where this is going.

I know this is odd, but it's very useful, see aardvark for an example.

So here is how it looks like in FF, opera, safari and chrome :

alt text http://img243.imageshack.us/img243/429/captureyv.png

and here is how it looks like in ie 8 :

alt text http://img190.imageshack.us/img190/7196/capture1dv.png

I immediately thought of a box model problem, but isn't it suppose to make it narrower ? and anyway, I used jquery to get the width and height, which is supposed to prevent this kind of problem. I went across the most known ie bugs, but can't find a match.

What do you think ?

ps : this is a bookmarklet, of course i tried to change the doctype on a local file and it worked, but in production, i won't be able to.

I use the ie dev toolbar to draw a border around element positioned as absolute :

alt text http://img21.imageshack.us/img21/3425/capture2uc.png

We can see the gap.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

电影里的梦 2024-08-14 12:26:25

使用 IE8 的开发工具栏检查底部“边框”div 的“实际”高度。确保它是“0”。

对底部 div 尝试以下操作。

<style type="text/css">
    #bottomBorder{
        /* Adding '!important' to each CSS rule 
           will make sure nothing else in your code is 'overwriting'
           that rule. (doesn't work for IE6)
        */
        line-height:0 !important; 
        font-size:0 !important;
        height:0 !important;
        border-bottom:solid 4px red;
        position:absolute;
    }
</style>

或者尝试:

<style type="text/css">
    #bottomBorder{
        border-top:solid 4px red;
    }
</style>

我的想法是 IE 不会让你将 div 设置为 0px 高度。我以前在 div 上见过这个。

Check the "actual" height of the BOTTOM "border" div with IE8's Developer toolbar. Make sure it is "0".

Try the following for that bottom div.

<style type="text/css">
    #bottomBorder{
        /* Adding '!important' to each CSS rule 
           will make sure nothing else in your code is 'overwriting'
           that rule. (doesn't work for IE6)
        */
        line-height:0 !important; 
        font-size:0 !important;
        height:0 !important;
        border-bottom:solid 4px red;
        position:absolute;
    }
</style>

OR try:

<style type="text/css">
    #bottomBorder{
        border-top:solid 4px red;
    }
</style>

What I'm thinking is that IE won't let you set a div to 0px height. I've seen this on divs before.

冷情妓 2024-08-14 12:26:25

我认为你应该摆弄你的 DOCTYPE 因为这通常会让 IE 朝着正确的方向发展

I think you should fiddle with your DOCTYPE as this usually gets IE going in the right direction

蓝色星空 2024-08-14 12:26:25

我认为这个问题与边距和填充有关。您的 DIV 中有任何信息或间隔吗?这可能会导致您没有考虑到的额外空间。

我会调整 div 的 margin:0;边框折叠:折叠;

另外,正如您所提到的,在底部 DIV 上,您应该将其设置为顶部边框,以尝试防止由于 DIV 本身内的任何边距或间距而出现此类间隙。

I would assume this issue has something to do with margins and padding. Do you have any information or spacers inside of your DIVs? This could result in extra space that you did not account for.

I would adjust the divs with margin:0; border-collapse:collapse;

Also, as you had mentioned, on your bottom DIV you should have that set to its top border to try and prevent such gaps from occurring due to any margins or spacing within the DIV itself.

来世叙缘 2024-08-14 12:26:25

难道 IE8 没有将边框的高度作为其高度参数的一部分吗?也尝试添加边框的大小。

Could it be that IE8 is not including the height of the border as part of its height parameter? Try adding the size of the border as well.

酒中人 2024-08-14 12:26:25

好的,我现在没有解决方案,但我只是显示底部 div 边框顶部而不是其边框底部,目前看起来足够好。如果有人更了解的话,他仍然受到欢迎。

Ok,I have no solution for now, but I just display the bottom div border top instead of its border bottom and it looks good enought for now. If any one knows better, he's still welcome.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文