CSS - 当“right:0px”出现时,绝对定位的 div 不会粘在右边缘。在IE6中
我在此处找到了一个示例使用单个图像使用圆角。我已经在 IE7+ 和 FireFox 中完美运行了。
以下是选项卡布局示例:
<div class="tab"><div class="corner TL"></div><div class="corner TR"></div>
<div class="inner"><p>Test 1</p></div>
</div>
<div class="tab"><div class="corner TL"></div><div class="corner TR"></div>
<div class="inner"><p>Test - 2</p></div>
</div>
<div class="tab"><div class="corner TL"></div><div class="corner TR"></div>
<div class="inner"><p>Test - 3</p></div>
</div>
以下是我的 CSS 样式:
.corner
{
background:url(../Images/LightCorner.gif);
position:absolute;
width:13px;
height:13px;
overflow:hidden;
}
.inner
{
position:relative;
padding:13px;
margin:0px;
}
.inner p
{
padding:0px;
}
.tab
{
color:#FFF;
float:left;
font-weight:bold;
margin-right:5px;
position:relative;
text-align:center;
}
.tab p
{
margin:0px;
padding:0px;
}
.tab
{
background:#B5B5B5;
}
.TL
{
top:0px;
left:0px;
background-position:0px 0px;
}
.TR
{
top:0px;
right:0px;
background-position:-13px 0px;
}
.TL, .TR
{
margin:0px;
padding:0px;
position:absolute;
}
问题是,当我的 div 的宽度是偶数时,我最终会得到 1px 的右侧边框,就好像右上角的 div 实际上被定位为 right:1px 一样。当宽度为奇数时,我看不到选项卡右侧的灰色,并且 div 按预期显示。
为什么右上角的 div 没有正确定位在 right:0px 处?当选项卡宽度为偶数时,为什么在 IE6 中最终会出现 1px 间隙?
I found an example here of using rounded corners using a single image. I've got this working perfectly in IE7+ and FireFox.
The following is an example tab layout:
<div class="tab"><div class="corner TL"></div><div class="corner TR"></div>
<div class="inner"><p>Test 1</p></div>
</div>
<div class="tab"><div class="corner TL"></div><div class="corner TR"></div>
<div class="inner"><p>Test - 2</p></div>
</div>
<div class="tab"><div class="corner TL"></div><div class="corner TR"></div>
<div class="inner"><p>Test - 3</p></div>
</div>
The following is my CSS Style:
.corner
{
background:url(../Images/LightCorner.gif);
position:absolute;
width:13px;
height:13px;
overflow:hidden;
}
.inner
{
position:relative;
padding:13px;
margin:0px;
}
.inner p
{
padding:0px;
}
.tab
{
color:#FFF;
float:left;
font-weight:bold;
margin-right:5px;
position:relative;
text-align:center;
}
.tab p
{
margin:0px;
padding:0px;
}
.tab
{
background:#B5B5B5;
}
.TL
{
top:0px;
left:0px;
background-position:0px 0px;
}
.TR
{
top:0px;
right:0px;
background-position:-13px 0px;
}
.TL, .TR
{
margin:0px;
padding:0px;
position:absolute;
}
The issue is that when my div's width is an even number, I end up with a 1px right-hand border, as though the top right div is actually being positioned as right:1px. When the width is an odd number I do not see the right hand grey colour of the tab and the div is displayed as expected.
The image I am using can be found here. A full example can be found here.
Why is the top right div not being positioned correctly at right:0px? Why do I end up with a 1px gap in IE6 when the tab width is an even number?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您的代码没有任何内容,这是 Internet Explorer 6 中的一个错误。当将事物绝对定位到右侧或底部时,实际位置将四舍五入为 2px,当总宽度/高度为 1px 时,给出 1px“边距”偶数(或奇数)。不幸的是,您需要 JavaScript 来解决这个问题。
你可以查看这个例子(我写的),慢慢调整IE6的大小窗口,逐像素。您会注意到底部和右侧框的位置仅每两个像素更新一次。另一个人也在他的网站上发现并记录了这个错误。
我已经编写了一个来修复定位顶部和底部时的高度计算,并将高度保留为自动。我在 此脚本 上使用vialink.com.br/" rel="nofollow noreferrer">此网站。根据您的原因,可以修改此脚本以根据
available_width-(right+width)
计算左偏移量。There is nothing with your code, it is a bug in Internet Explorer 6. When absolute-positioning things to the right or to the bottom, the actual position will be rounded to 2px, giving 1px "margin" when the total width/height is even (or odd). Unfortunately, you need JavaScript to fix that.
You can check this example (written by me) and slowly resize the IE6 window, pixel-by-pixel. You will notice that the position of bottom and right boxes will be updated only once every two pixels. Another guy has also found and documented this bug on his site.
I've already written one to fix height-calculation when positioning top and bottom, and leaving height as auto. I use this script on this site. In your cause, this script can be modified to calculate the left-offset based on
available_width-(right+width)
.你试过
身体吗{
保证金:0;
}
Have you tried
body {
margin: 0;
}
尝试使用:
对于 IE6
Try with:
for IE6