0

我正在使用 html 、 css 和 javascript 开发一个网站。这些按钮在每个浏览器中的显示方式都不同。以下是同一页面不同浏览器的截图:

IE浏览器 : 在此处输入图像描述

火狐: 在此处输入图像描述

我实际上打算将它显示为在 firefox 中显示的那样。这里我正在使用的一些 css 代码:

#button{
float: left;
width: 500px;
height: 50px;
line-height: 50px;
background-color: #06C;
padding-left: 20px;

-moz-border-radius:10px;
-webkit-border-radius:10px;
border-radius:10px;

-webkit-box-shadow: 0px 1px 1px 0px rgba(255,255,255, .2), inset 0px 1px 1px 0px rgb(0,0,0);
-moz-box-shadow: 0px 1px 1px 0px rgba(255,255,255, .2), inset 0px 1px 1px 0px rgb(0,0,0);
box-shadow: 0px 1px 1px 0px rgba(255,255,255, .2), inset 0px 1px 1px 0px rgb(0,0,0);

background-image: -webkit-gradient(
    linear,
    left bottom,
    left top,
    color-stop(0, #60B842),
    color-stop(0.85, #7FD13D)
);
background-image: -moz-linear-gradient(
    center bottom,
    /* change these to change the button colors */
    #B58515 0%,
    #DC9E1F 85%
);

/* change this to change the text color and font type */
color:#fff;
font-family:arial,helvetica,sans-serif;
font-size:17px;
font-weight:bold;
text-shadow:1px 1px 1px #4c9434;
    }

    #button:hover{
background-image: -webkit-gradient(
    linear,
    left bottom,
    left top,
    color-stop(0, #6DD14B),
    color-stop(0.85, #85DB40)
);
background-image: -moz-linear-gradient(
    center bottom,
    /* change these colors to change the mouse hover colors */
    #E17100 0%,
    #FF9326 85%
);
box-shadow:0 2px 0 #5EA839;
    }

使用渐变可能存在一些问题。有人可以建议我进行任何更改或其他编码方式,以使网页在不同浏览器中看起来相同吗?

4

5 回答 5

1

我通常使用Colorzilla 的 Ultimate CSS Gradient Generator来生成跨浏览器的 CSS 渐变代码。

于 2013-01-10T06:04:29.093 回答
0

所有浏览器都支持渐变属性使用这个

 background: -moz-linear-gradient(top, white, #1a82f7);/*Mozila*/
    background: -o-linear-gradient(top, white, #1a82f7); /*opera*/
    background: -webkit-linear-gradient(top, white, #1a82f7);/*Chrome and safari*/
    filter: progid:DXImageTransform.Microsoft.gradient(startColorStr='white',    EndColorStr='#1a82f7'); /*IE*/
于 2013-01-10T07:21:56.880 回答
0

除此之外-webkit-gradient()-moz-gradient()您还需要使用 IE 和其他浏览器的前缀。

例子:

#linearBg2 {
  /* fallback */
  background-color: #1a82f7;
  background: url(images/linear_bg_2.png);
  background-repeat: repeat-x;

  /* Safari 4-5, Chrome 1-9 */
  background: -webkit-gradient(linear, 0% 0%, 0% 100%, from(#1a82f7), to(#2F2727));

  /* Safari 5.1, Chrome 10+ */
  background: -webkit-linear-gradient(top, #2F2727, #1a82f7);

  /* Firefox 3.6+ */
  background: -moz-linear-gradient(top, #2F2727, #1a82f7);

  /* IE 10 */
  background: -ms-linear-gradient(top, #2F2727, #1a82f7);

  /* Opera 11.10+ */
  background: -o-linear-gradient(top, #2F2727, #1a82f7);
}

资源

在这里阅读更多

请注意,IE 9 及更早版本不支持渐变

于 2013-01-10T05:57:46.477 回答
0

发生的事情是 IE 完全忽略了你的渐变 css。您必须添加一个“过滤器”才能使渐变出现在 IE 中。

此页面将帮助您创建跨浏览器渐变。

于 2013-01-10T05:59:03.187 回答
0

下面是一组 CSS 渐变,它们对您的跨浏览器兼容性很有用:

/* IE10 Consumer Preview */
background-image: -ms-linear-gradient(top left, #FFFFFF 0%, #00A3EF 100%);

/* Mozilla Firefox */
background-image: -moz-linear-gradient(top left, #FFFFFF 0%, #00A3EF 100%);

/* Opera */
background-image: -o-linear-gradient(top left, #FFFFFF 0%, #00A3EF 100%);

/* Webkit (Safari/Chrome 10) */
background-image: -webkit-gradient(linear, left top, right bottom, color-stop(0, #FFFFFF), color-stop(1, #00A3EF));

/* Webkit (Chrome 11+) */
background-image: -webkit-linear-gradient(top left, #FFFFFF 0%, #00A3EF 100%);

/* W3C Markup, IE10 Release Preview */
background-image: linear-gradient(to bottom right, #FFFFFF 0%, #00A3EF 100%);
于 2013-01-10T08:23:37.787 回答