【问题标题】:Border radius, background image, background gradient, and IE8, IE10边框半径、背景图片、背景渐变以及IE8、IE10
【发布时间】:2013-05-10 17:40:12
【问题描述】:

我有一个带有边框半径、背景渐变和背景图像的 div,可在 FireFox 中使用,但在 IE8 或 IE10 中却不行。渐变和背景图片在 IE8 中工作,但是当我应用边框半径时,边框消失了。

.add-to-carttest {
border: 1px solid #004f9e;
padding: 5px 5px 5px 50px;
width:100px;
height: 40px;
font-weight:bold;
background: url(https://www.storesmart.com/mm5/graphics/00000001/add-to-cart-plus.png) no-repeat, -webkit-gradient(linear, 0 0, 0 bottom, from(#e1f0ff), to(#73b9ff));
background: url(https://www.storesmart.com/mm5/graphics/00000001/add-to-cart-plus.png) no-repeat, -webkit-linear-gradient(#e1f0ff, #73b9ff);
background: url(https://www.storesmart.com/mm5/graphics/00000001/add-to-cart-plus.png) no-repeat, -ms-linear-gradient(#e1f0ff, #73b9ff);
background: url(https://www.storesmart.com/mm5/graphics/00000001/add-to-cart-plus.png) no-repeat, -o-linear-gradient(#e1f0ff, #73b9ff);
background: url(https://www.storesmart.com/mm5/graphics/00000001/add-to-cart-plus.png) no-repeat, linear-gradient(#e1f0ff, #73b9ff);
background: url(https://www.storesmart.com/mm5/graphics/00000001/add-to-cart-plus.png) no-repeat, linear-gradient(#e1f0ff, #73b9ff);
-webkit-border-radius: 4px;
-moz-border-radius: 4px;
border-radius: 4px;
behavior: url(../../Graphics/PIE/PIE.htc);
position:relative;
filter: progid:DXImageTransform.Microsoft.gradient( startColorstr="#e1f0ff", endColorstr="#73b9ff",GradientType=0 ), progid:DXImageTransform.Microsoft.AlphaImageLoader(src="https://www.storesmart.com/mm5/graphics/00000001/add-to-cart-plus.png");}

【问题讨论】:

  • 另外,如何将背景图像定位集成到其中?我在所有这些行的“no-repeat”和“-webkit etc”之间插入了它,它在 FF 和 IE10 中工作,但在 IE8 中,图像没有定位。

标签: css background-image css3pie


【解决方案1】:

边框半径在 IE8 中不可用

http://www.quirksmode.org/css/backgrounds-borders/

哎呀 - 刚刚注意到您的行为条目...可能需要仔细检查您的路径

好的,这就是我想出的:

CSS:

.common
{
    width: 100px;
    height: 40px;
    border: 1px solid #004f9e;
    padding: 5px 5px 5px 50px;
    margin: 0px;
    font-weight: bold;
    -webkit-border-radius: 4px;
    -moz-border-radius: 4px;
    border-radius: 4px;
    !behavior: url(../../Graphics/PIE/PIE.htc);
    position: relative;
    border-collapse:collapse;
}

.add-to-carttest
{
    background-image: url('https://www.storesmart.com/mm5/graphics/00000001/add-to-cart-plus.png');
    background-position:20px 20px;
    background-repeat:no-repeat;
    background-attachment:fixed;
    top:-6px;
    left:-51px;
}

.gradient
{
    background: -moz-linear-gradient(#e1f0ff, #73b9ff); 
    background: -webkit-gradient(linear, 0 0, 0 bottom, from(#e1f0ff), to(#73b9ff));
    background: -webkit-linear-gradient(#e1f0ff, #73b9ff);
    background: -ms-linear-gradient(#e1f0ff, #73b9ff);
    background: -o-linear-gradient(#e1f0ff, #73b9ff);
    background: linear-gradient( #e1f0ff, #73b9ff);
    filter: progid:DXImageTransform.Microsoft.gradient( startColorstr='#e1f0ff', endColorstr='#73b9ff',GradientType=0 );
    -ms-filter: "progid:DXImageTransform.Microsoft.gradient( startColorstr='#e1f0ff', endColorstr='#73b9ff',GradientType=0 )";
}

HTML:

<div class="common gradient">
    <div class="common add-to-carttest"></div>
</div>

似乎 IE8 中的渐变过滤器覆盖并隐藏或重新定位背景图像,因为渐变本身似乎呈现为图像。所以我分解了css并嵌套了div。然后重新定位内部 div 以覆盖外部。这似乎可行,但不优雅,但兼容。

此外,通过“左下”语法定位似乎只适用于较新的浏览器,所以我按像素位置定位背景图像

希望对你有帮助

【讨论】:

  • 如果我取出所有“背景:url”的东西,半径就可以了。不知道我做错了什么。
  • 对于它的价值,它可能不是你,而是 IE8 :) - 仍在努力寻找解决方案
  • 感谢您的帮助。我可能应该从一开始就这么说,但我正在尝试设计一个按钮的样式。我认为我不能将 div 放入按钮(输入)中。但你已经回答了我的问题:我正在尝试一些对 IE 来说过于雄心勃勃的东西。我可能应该将我的小图像和渐变整合到一个大背景图像中,或者只是将整个按钮制作为图像。谢谢!
  • 您不能将 div 放入按钮中...但是您可以将 onclick 添加到 div 中
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多