css - 我是否正确地子类化了我的 CSS?

标签 css subclassing css-cascade

我正在为我的网站制作一组按钮,我需要一些专业的见解。

为了减少 CSS 膨胀,我想将我的按钮子类化为不同的颜色,ex .button.blue 。

以后会不会出现以下问题? (假设我不做一类只是.blue) 我是否必须改用 .button.button-blue 之类的东西?

.button {
  display:inline-block;
  padding: 9px 18px;
  margin: 20px;
  text-decoration: none;
  font-family: Arial, Helvetica, sans-serif;
  font-size: 12px;
  font-weight: bold;
  text-align: center;
  background: #FFE150;
}
.button.blue {
  background: #49b8e7;
  border:1px solid #54abcf;
  border-bottom:1px solid #398fb4;
  color:#FFF
  text-shadow: 0 1px 0 rgba(255,255,255, 0.5);
}
.header{
  height: 50px;
}
.header.blue {
  background: blue;
  color: #fff;
}

最佳答案

如果您希望它们像这样工作,那么您拥有的多类将可以正常工作:

<div class="button blue">
Will use .button and .button.blue
</div>

<div class="button">
Will only use .button
</div>

<div class="header blue">
Will  use .header and .header.blue
</div>

<div class="header">
Will only use .header
</div>

<div class="blue">
Will use neither of the .blue declarations because it doesn't contain header or button.
</div>

关于css - 我是否正确地子类化了我的 CSS?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9212955/

相关文章:

CSS :after element relative position

html - CSS 箭头向下箭头

javascript - Angular 指令中的 element.css 不更新元素的 css

c# - 决定需要哪个子类的最佳方法

swift - 返回 self 的协议(protocol)功能

iphone - 在 iPhone 中修改 MWPhotoBrowser

javascript - 溢出隐藏和 URL 中的 ID。内容未显示,跳到顶部

CSS级联优先级的起源和重要性

基于样式表中顺序的 CSS 特异性/优先级?