ams*_*ams 2 css css-specificity
考虑<div class="well well-large well-small" />来自 twitter bootstrap https://github.com/twitter/bootstrap/blob/master/less/wells.less的以下样式
// Base class
.well {
min-height: 20px;
padding: 19px;
margin-bottom: 20px;
background-color: @wellBackground;
border: 1px solid darken(@wellBackground, 7%);
.border-radius(@baseBorderRadius);
.box-shadow(inset 0 1px 1px rgba(0,0,0,.05));
blockquote {
border-color: #ddd;
border-color: rgba(0,0,0,.15);
}
}
// Sizes
.well-large {
padding: 24px;
.border-radius(@borderRadiusLarge);
}
.well-small {
padding: 9px;
.border-radius(@borderRadiusSmall);
}
Run Code Online (Sandbox Code Playgroud)
CSS 如何决定在这种情况下应用哪种填充?它是 19px、24px、9px 还是未定义的值?我对特异性的理解是初步的,似乎在这种情况下,.well .well-large and .well-small
如果特异性相同,则按定义的顺序应用它们。
例子:
.a {
color: red;
}
.b {
color: blue;
}
Run Code Online (Sandbox Code Playgroud)
<span class="a b">this is blue</span>
<span class="b a">this is blue</span>
Run Code Online (Sandbox Code Playgroud)
如果您好奇,这里是样式级联的规则。