asp.net - 使用标签样式而不是类样式

标签 asp.net css twitter-bootstrap

我正在使用 ASP.NET Web Forms 开发应用程序和 我想用 bootstrap.css风格。 问题是,对于一个按钮,一些属性 从定义的默认 Style.css 使用 标签,而 Bootstrap 标签是为“btn btn-primary”之类的类定义的。 这是 HTML 标记

<asp:Button ID="Button1" type="button" CssClass="btn btn-primary" runat="server" Text="View data" OnClick="Button1_Click" />

对于默认的Style.css
input[type="submit"], input[type="button"], button {<br/> background-color: #d3dce0;<br/> border: 1px solid #787878;<br/> cursor: pointer;<br/> font-size: 1.2em;<br/> font-weight: 600;<br/> padding: 7px;<br/> margin-right: 8px;<br/> width: auto;<br/> }

和自举
.btn-primary {<br/> color: #ffffff;<br/> background-color: #428bca;<br/> border-color: #357ebd;<br/> }<br/>

我注意到的主要事情是使用的背景颜色不是来自 Bootstrap 但形成 Style.css。

为什么会这样?

最佳答案

这是由于特殊性。 The rules are :

  • count 1 if the declaration is from is a 'style' attribute rather than a rule with a selector, 0 otherwise (= a) (In HTML, values of an element's "style" attribute are style sheet rules. These rules have no selectors, so a=1, b=0, c=0, and d=0.)
  • count the number of ID attributes in the selector (= b)
  • count the number of other attributes and pseudo-classes in the selector (= c)
  • count the number of element names and pseudo-elements in the selector (= d)

Concatenating the four numbers a-b-c-d (in a number system with a large base) gives the specificity.

这意味着:

input[type="button"]   has specificty   0,0,1,1
.btn-primary           has specificty   0,0,1,0

第一个更大,所以它将应用于第二个,而不管顺序如何。

关于asp.net - 使用标签样式而不是类样式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18282392/

相关文章:

c# - 本地主机上的 .net HTTP_X_FORWARDED_FOR NULL

python - 抓取包含::之前的网页

javascript - Pagespeed - 延迟加载幻灯片图像

css - 带有 Bootstrap 的 Meteor margin-bottom

javascript - 自举网格间距不正确

asp.net - 如何阻止 ASP.NET 在首次加载时从 bin 加载所有程序集

php - 是否可以从 SQL Server 创建文本格式的列表,然后由 PHP Cron 作业处理?

css - @font-face 用于 IE8 奇怪的行为

html - Bootstrap 栏不再关注

c# - 枚举 int 列表<GradeRange>