html - css 当对同一个 css 属性使用多个类时

标签 html css

我不太了解css规则。 我有多个具有相同属性(例如“宽度”)的类。
将这些类设置为 Html 标签时, 谁的宽度属性设置为该标签?
例如。

.main{
   width:600px;
   border:1px solid #000;
}

.rule1{
  width:400px;
  min-height:10px;
}

.rule2{
  width:300px;
  background:#aaa;
}
<div class="main rule1 rule2">
  Which rule's width property is set?
</div>

最佳答案

.rule2{
  width:300px;
  background:#aaa;
}

这个定义了标签的宽度,因为它位于末尾。当一个标签有多个类,并且所有类都有一个通用样式时,最后一条规则将覆盖所有以前的规则。

关于html - css 当对同一个 css 属性使用多个类时,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44274869/

相关文章:

HTML & CSS Div 类未加入

javascript - 在 Firefox 中覆盖 html?

html - Bootstrap 内容不会随数据扩展

jquery - 数据表问题和不需要的水平滚动条

css - 在悬停时显示 DIV - 自动溢出

html - 如何定义绝对定位元素的 anchor ?

html - CSS @media 查询未按预期工作

javascript - 选择标签的双击事件。 Firefox 的问题

javascript - 在 bootstrap nav-pill 中使用 div

css - transition 属性会影响浏览器性能吗?