html – IE9圆角和CSS背景渐变生活在一起?

前端之家收集整理的这篇文章主要介绍了html – IE9圆角和CSS背景渐变生活在一起?前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我在IE9中遇到了一个奇怪的事情,试图得到一个背景渐变显示

基本上我正在应用多个类到一个容器对象。

  1. <div class="gradient corners"></div>

使用这个CSS。

  1. .gradient {
  2. background-color: #96A7C5;
  3. background-image: -webkit-gradient(
  4. linear,left bottom,left top,color-stop(0.19,#6C86AD),color-stop(0.6,#96A7C5)
  5. );
  6. background-image: -moz-linear-gradient(
  7. center bottom,#75A33A 19%,#8DC447 60%
  8. );
  9.  
  10. .corners {
  11. -webkit-border-radius: 10px;
  12. -moz-border-radius: 10px;
  13. border-radius: 10px;
  14. }

要在IE中获得渐变,我将过滤器垃圾应用到我的.gradient类。

  1. filter: progid:DXImageTransform.Microsoft.gradient(startColorstr='#8DC447',endColorstr='#75A33A');

有了这个渐变效果,但是我的圆角就消失了。

所以我尝试放置过滤器声明的条件。

  1. <!--[if IE]>
  2. filter: progid:DXImageTransform.Microsoft.gradient(startColorstr='#8DC447',endColorstr='#75A33A');
  3. <![endif]-->

这带回了我的角落,但渐渐消失。

解决方法

渐变将出来在IE9的圆角,所以现在最好的解决方添加一个额外的div:
  1. <div class="corners"><div class="gradient"></div></div>

并隐藏.corners的溢出

  1. .corners {
  2. -webkit-border-radius: 10px;
  3. -moz-border-radius: 10px;
  4. border-radius: 10px;
  5.  
  6. overflow: hidden;
  7. }

我推荐这个类似Photoshop的工具来创建跨浏览器渐变:http://www.colorzilla.com/gradient-editor/

而这一个创建border-radius:
http://border-radius.com/

猜你在找的HTML相关文章