css - CSS只适用于IE9,其他css都适用

标签 css internet-explorer-9

我必须将 border-radius CSS 属性应用于按钮,但前提是浏览器不是 Internet Explorer 9。否则我想使用 background-image 属性(property)。我尝试使用条件注释为 IE9 应用 background-image,但它不起作用(“general”CSS 中的 border-radius 属性正在应用于 IE9此外,而不是 background-image)。

如何更改它以使其根据浏览器版本应用所需的 CSS?

/*For IE9*/
<!--[if lte IE 9]>
.PopupBtn
{
  background-image: url("../Images/new-btn.png");
  height: 28px;
  width: 99px;
  border-left-width: 0px;
  border-top-style: none;
  border-right-style: none;
  border-bottom-style: none;
  border-left-style: none;
  cursor: pointer;
}
<![endif]-->

/*Style.css(general)*/
.PopupBtn
{
  -moz-box-shadow: inset 0px 2px 1px 0px #0d0d0d;
  -webkit-box-shadow:inset 0px 2px 1px 0px #0d0d0d;
  box-shadow:inset 0px 2px 1px 0px #0d0d0d;
  background:-webkit-gradient(linear, left top, left bottom, color-stop(0.05, #fffcff), color-stop(1, #000000));
  background:-moz-linear-gradient(center top, #fffcff 5%, #000000 100%);
  filter:progid:DXImageTransform.Microsoft.gradient(startColorstr='#fffcff', endColorstr='#000000');
  background-color:#fffcff;
  -moz-border-radius:22px;
  -webkit-border-radius:22px;
  border-radius:22px;
  display:inline-block;
  color:#fcfcfc;
  font:bold 13px  trebuchet ms;
  text-decoration:none;
  text-shadow:1px 0px 0px #000000;
  min-width:90px;
  height:30px;
  cursor:pointer;
  border-style:none;
}

最佳答案

为此最好使用 jQuery。

if ($.browser.msie  && parseInt($.browser.version, 10) == 9)
 $('.PopupBtn').css({'background-image':'url(../Images/new-btn.png)','height':'28px','width':'99px'});

参见 http://api.jquery.com/css/好处是你不仅要使用更少的代码,而且你可以调整一切,而不仅仅是css。这只是一个示例,您必须填写其余部分:)

关于css - CSS只适用于IE9,其他css都适用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14744969/

相关文章:

javascript - angular.element ('#someId' ).scope() 在 IE 9 中返回未定义

Jquery .on() 不工作

css - 如何让ctags + scss发挥出色

javascript - javascript中的可扩展div

javascript - 如何制作左右面板,并能够在它们之间滑动分隔线?

javascript - Jquery 使 div 具有页面的全宽和高度并响应

javascript - jquery "slideToggle()"不工作

html - 强制 IE8 或 IE9 文档模式为标准

css - 无法在 IE9 的怪癖模式下减小 div 的宽度/高度

html - 在输入下方显示验证消息(IE9 和 IE7)