asp.net - 如何覆盖 site.master 页面中的部分样式?

标签 asp.net html css

我正在开发一个 ASP.NET web 应用程序,在它的站点主控中(在 ContentPlaceHolder3 中)我放置了一些应用于整个网站的 css 样式。此样式的部分内容如下:

.Welcome { 
width:531px; 
margin:5px 15px; 
float:left; 
padding:5px 10px; 
}
.Welcome ul { 
width:250px; 
float: left; 
margin:5px 3px; 
padding:0; 
list-style:none; 
}
.Welcome li {
background:url(images/ul_li.gif) left no-repeat;
padding:5px 20px; 
margin:0; 
font: normal 12px Georgia, "Times New Roman", Times, serif; /* the original font-size was 11px. */ 
color:#5c5c5c; 
}

现在,在其中一个网站页面中,我想将一些内容放入具有以下特定样式的 ContentPlaceHolder 中:

/*body { font: 0.8em Arial, sans-serif; }*/
        .tipsMenu { padding: 0; clear: both; }
        .tipsMenu li { display: inline; }
        .tipsMenu li a { background: #ccf; padding: 10px; float:left; border-right: 1px solid #ccf; border-bottom: none; text-decoration: none; color: #000; font-weight: bold;}
        .tipsMenu li.active a { background: #eef; }
        .tipsContent { float: left; clear: both; border: 1px solid #ccf; border-top: none; border-left: none; background: #eef; padding: 10px 20px 60px; width: 400px; }

编辑: *当我尝试这样做时,我从 site.master 页面中的 CSS 文件中获得了一些样式。那么如何用内联样式覆盖母版页中的样式呢?*

最佳答案

除了确保在 site.master 页面中嵌入的样式之后加载特定样式之外,您还可以尝试以下几件事:

1.检查css specificity你的新风格。基本上,您需要确保新样式中使用的选择器比其他样式表中使用的选择器更具体。简而言之,内联样式比 id 更具体,id 比类更具体,类比 html 元素更具体。例如:

#selector {
    // High specificity
}
.selector1 .selector2 .selector3 {
    // Less specificity than #selector, #selector styles applied
}

2.!important 子句添加到样式中。这会覆盖特异性规则并强制浏览器使用重要的样式。尽管更简单,但出于可维护性等原因,不推荐使用此方法。像这样:

.tipsMenu { padding: 0 !important; clear: both !important; }
.tipsMenu li { display: inline !important; }

关于asp.net - 如何覆盖 site.master 页面中的部分样式?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8524329/

相关文章:

html - 带有评论框的文本溢出

javascript - 某些用户滚动后强制向下滚动到特定点 [React]

asp.net - 生成 ModelState 字典的键

javascript - 这两个代码片段之间的功能区别是什么?

mysql - 选择每首歌曲中观看次数最多的视频

javascript - 从树中获取 id

html - 当悬停最后一个 child 时,嵌套的 div 也悬停在父级上

css - 将 div 限制在浏览器窗口的底部

c# - MVCMailer smtp mailsettings 以编程方式设置配置设置

asp.net - 在 Windows 窗体中不调用 SqlConnection.Close() - 为什么它有时会起作用