我假设 SharePoint 母版页与 ASP.NET (MVC) 中的母版页相同。因此这根本不应该是一个问题。
<!--[if lt IE 7 ]> <html class="ie6"> <![endif]-->
<!--[if IE 7 ]> <html class="ie7"> <![endif]-->
<!--[if IE 8 ]> <html class="ie8"> <![endif]-->
<!--[if IE 9 ]> <html class="ie9"> <![endif]-->
<!--[if (gt IE 9)|!(IE)]><!--> <html> <!--<![endif]-->
前面的代码所做的只是在 HTML 标记上设置不同的 CSS 类,具体取决于访问该站点的浏览器。这样您就可以覆盖任何给定浏览器 (IE) 的某些样式表。
site.css
.coloredBackground
{
background-color: #FF0000; //red
}
.ie6 .coloredBackground
{
background-color: #00FF00; //green
}
.ie8 .coloredBackground
{
background-color: #0000FF; //blue
}
在此示例中,使用 Firefox、Opera、Safari、IE7、9、10 浏览的用户将看到红色背景。对于 IE6,背景颜色被绿色覆盖,而在 IE8 中,背景颜色被蓝色覆盖。
您的 CSS 注册如下所示:
<SharePoint:CSSRegistration Name="site.css" runat="server" />
正如您所看到的,不再需要在 CSS 注册中设置 ConditionalExpression,因为您已经通过在 HTML 元素上设置特定的类来切换使用的样式表。
Update:
另一种可能性是使用 SharePoint aspx 控件上的条件表达式属性,根据浏览器版本包含另一个样式表文件。
<SharePoint:CSSRegistration Name="ie6.css" ConditionalExpression="lt IE 7" runat="server" />
<SharePoint:CSSRegistration Name="ie7.css" ConditionalExpression="IE 7" runat="server" />
<SharePoint:CSSRegistration Name="ie8.css" ConditionalExpression="IE 8" runat="server" />
<SharePoint:CSSRegistration Name="ie9.css" ConditionalExpression="IE 9" runat="server" />
缺点是你可能会遇到 css 优先级问题,因为.ie*
html 元素上缺少 class,因此不会推翻.class-to-override-if-specific-ie-version
。您可以使用以下方法解决此问题!important
ie 特定样式表文件中的规则。