2

我正在尝试第一次使用 razor views 创建和启动一个网站(C# .Net MVC)。

我在网站上大量使用了线性渐变,自从启动以来,我意识到 IE 9 及更低版本不支持渐变

我想根据浏览器类型和版本选择渐变样式。

例如:

@if(browser is IE 9 and under){
style="background: #ffffff;
}
Else{
style="background:linear-gradient(to bottom, #ffffff 0%,#ffffff 100px,#b8dbff 100%);
}

如何在 Razor 视图中检测浏览器类型和版本?

过滤与线性渐变不兼容的浏览器版本的最简单方法是什么?

向前端开发人员致敬,我不知道这些跨浏览器问题是这样的问题。

当浏览器中的某些内容无法正常工作时,我自己经常抱怨

4

2 回答 2

0

You can use the Razor engine to serve a different view based on the caller, but it sounds like your situation can be handled with HTML/CSS.

If IE9 is your only problem, you can use conditional comments and include extra styles/stylesheet.

<!--[if IE 9]>
<style>
   #foo { background-color: #fff; }
</style>
<![endif]-->

But for your particular question, you should be able do something even more simple and just modify your stylesheet:

body{
    /* all browsers */
    background: red;

    /* newer browsers overwrite the previous value; old browsers ignore */
    background: linear-gradient( to left top, blue, red); 
}

IE9 doesn't know what "linear-gradient" means, and so ignores it. This is defined behavior upon which you can rely.

Demo: http://fiddle.jshell.net/K67yd/2/show/

于 2013-10-17T23:03:46.987 回答
0

你应该看看 Modernizr,一个用于检测浏览器支持功能的 JavaScript 库。我想它会完成这项工作。

您可能会在这里找到一些东西:http: //modernizr.com/docs/#features-css

还有一个很好的视频来理解这个概念:http ://css-tricks.com/video-screencasts/126-using-modernizr/

于 2013-10-17T21:48:44.313 回答