IE6 中背景图像位置保持在顶部,而不是底部
我想创建一个流体/灵活的弧形角盒。 理想情况下,它应该是多功能的,因此内容可以出现在盒子的顶部/底部。
按理说,我应该能够使用 4 个元素 (div) 和一个图像。 我几乎可以在所有浏览器中使用它 - 除了 IE6。
我已经修改了 http://www.schillmania.com/projects/dialog2/basic 的代码.html 这样我就有了以下标记和CSS;
<div class="boxtl boxcontent">
<div class="boxtr boxcontentside">tr</div>
<p>This is the top half of the box</p>
<p> content! </p>
<p> content! </p>
</div>
<div class="boxbl boxcontent2">
<div class="boxbr boxcontentside">br</div>
<p>This is the bottom half of the box</p>
<p> content! </p>
<p> content! </p>
</div>
.boxtl, .boxtr, .boxbl, .boxbr {position:relative; zoom:1; background: url(../revised-images/testbox2.png) no-repeat 0 0; _background: url(../revised-images/testbox2ie.png) no-repeat 0 0; height:auto;}
.boxtl {margin-right:20px; }
.boxtr {margin-right:-20px; width:20px; height:20px; position:absolute; left:100%; top:0; background-position: 100% 0; }
.boxbl {margin-right:20px; background-position: 0 100%;}
.boxbr {margin-right:-20px; width:20px; position:absolute; left:100%; top:0; background-position: 100% 100%;}
.boxcontent {padding:20px 0 1px 20px; position:relative; zoom:1; _overflow-y:hidden; width:auto;}
.boxcontentside {height:100%; _height:2000px;}
我使用了一个大的单框图像(2000px H/W)。 这个方法的想法是我可以使用 alpha 透明度(角、阴影等), 没有重叠等
。
问题是IE6;它拒绝执行任何类似于背景图像垂直定位的操作。我什至尝试将顶部 2 个 div(.tl 和 .tr)的背景位置更改为距离顶部 50%,但在 IE6 中,它保持在 0。
我尝试使用全/长手背景属性(背景-image/background Repeat/background-position)并且我尝试了x/y版本(background-position-x/background-position-y)等。
看来我是否使用_height:或_overflow-y:使 IE 拉伸所需高度的属性,它削弱了其垂直定位图像的能力。
我该怎么做?
I want to create a fluid/flexible curved corner box.
Ideally it should be versatile, so the content can appear in the top/bottom of the box.
By rights, I should be able to use 4 elements (divs) and a single image.
I can get this working in almost every browser - barring IE6.
I've modified code from http://www.schillmania.com/projects/dialog2/basic.html
So that I have the following markup and css;
<div class="boxtl boxcontent">
<div class="boxtr boxcontentside">tr</div>
<p>This is the top half of the box</p>
<p> content! </p>
<p> content! </p>
</div>
<div class="boxbl boxcontent2">
<div class="boxbr boxcontentside">br</div>
<p>This is the bottom half of the box</p>
<p> content! </p>
<p> content! </p>
</div>
.boxtl, .boxtr, .boxbl, .boxbr {position:relative; zoom:1; background: url(../revised-images/testbox2.png) no-repeat 0 0; _background: url(../revised-images/testbox2ie.png) no-repeat 0 0; height:auto;}
.boxtl {margin-right:20px; }
.boxtr {margin-right:-20px; width:20px; height:20px; position:absolute; left:100%; top:0; background-position: 100% 0; }
.boxbl {margin-right:20px; background-position: 0 100%;}
.boxbr {margin-right:-20px; width:20px; position:absolute; left:100%; top:0; background-position: 100% 100%;}
.boxcontent {padding:20px 0 1px 20px; position:relative; zoom:1; _overflow-y:hidden; width:auto;}
.boxcontentside {height:100%; _height:2000px;}
I've used a large single box image (2000px H/W).
The idea of this method is that I can use alpha transparency (corners, shadows etc.),
with no overlaps etc.
.
The problem is IE6; it refuses to do anything resembling vertical positioning of the background image. I even tried altering the background-position of the top 2 divs (.tl and .tr) to 50% from the top, but in IE6, it stays at 0.
I've tried using the full/long hand background properties (background-image/background repeat/background-position)and I've tried the x/y version (background-position-x/background-position-y) etc.
It seems if I use the _height: or the _overflow-y: properties to make IE stretch the needed height, it cripples its ability vertically position the image.
How can I do this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
正如@Dan 在评论中提到的,你真的不应该再使用这种圆角图像技术。
为此,您应该使用 CSS 属性
border-radius
。IE6-8不支持
border-radius
,但您可以使用CSS3Pie脚本向这些旧版本的 IE 添加对此属性的支持。现在,您不需要所有额外的标记,或所有不必要的类,或所有繁琐的 CSS。
CSS3Pie 的美妙之处在于它只能在 IE 中运行。在所有其他浏览器中,您将使用纯 CSS,它们将忽略 CSS3Pie 脚本。在 IE 中,是的,它是一个 javascript 解决方案,但它是轻量级的(通常比为角下载多个图像文件更轻),如果它不运行,则后退只是方角;这并不是世界上最糟糕的事情。
它还增加了对 IE 的支持,以实现许多其他有用的 CSS3 功能。
如果 CSS3Pie 的下载量对您来说太大了(33k),还有一些其他类似的项目可以做同样的事情,但功能较少。在 CSS3Pie 出现之前,我曾经推荐 HTMLRemix 相反。虽然只有 5k 左右,但还不够好。
As mentioned by @Dan in the comments, you really shouldn't use this kind corner image technique for rounded corners any more.
You should use the CSS property
border-radius
for this.IE6-8 doesn't support
border-radius
, but you can use the CSS3Pie script to add support for this property to these older versions of IE.Now you don't need all that extra markup, or all those unnecessary classes, or all that hairy CSS.
The beauty of CSS3Pie is that it only runs in IE. In all other browsers, you'll be using pure CSS, and they'll ignore the CSS3Pie script. In IE, yes, it's a javascript solution, but it's lightweight (typically lighter weight than downloading multiple image files for the corners), and if it doesn't run, the fall-back is simply square corners; not exactly the worst thing in the world.
It also adds support to IE for a number of other useful CSS3 features.
If the download weight of CSS3Pie is too much for you (it's 33k), there are a few other similar projects which do the same thing, but with fewer features. Before CSS3Pie came along, I used to recommend the one from HTMLRemix instead. That's only about 5k, but isn't as good.