我正在使用 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/