html - 如何轻松覆盖 Bootstrap CSS

标签 html css twitter-bootstrap

我想问一下,为什么在 custom.css 中需要使用 !important 来覆盖 bootstrap.css 中的一些样式
比如: 输入、按钮、导航栏等

例如:

.navbar{
 background :#52B3D9;
 border-radius:0px !important;
 border-top:4px solid #1E8BC3 !important;}

不使用 !important?

也可以覆盖 bootstrap.css

最佳答案

您需要编写一个比您正在覆盖的选择器更具体的选择器(或同样具体但稍后)。

A selector's specificity is calculated as follows:

  • count the number of ID selectors in the selector (= a)
  • count the number of class selectors, attributes selectors, and pseudo-classes in the selector (= b)
  • count the number of type selectors and pseudo-elements in the selector (= c)
  • ignore the universal selector
  • Selectors inside the negation pseudo-class are counted like any other, but the negation itself does not count as a pseudo-class.

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

关于html - 如何轻松覆盖 Bootstrap CSS,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27605854/

相关文章:

css - 我怎样才能让我的行 100% 宽?

html - CSS 高度有效但最小高度无效

html - 两个部分之间不需要额外的空间 - Bootstrap 3 中的背景图像原因

html - Css hover 在一个完全随机的元素上触发

html - 在同一个 html 页面中使用两个不同的 css

html - iframe 在父级内部的高度为零,没有高度和底部填充

html - Nodejs : Getting plain text from HTML but retaining ordered and unordered lists

html - Bootstrap 4 beta Nav 自动扩展

javascript - 缓存此选择器 css

javascript - Jquery 代码不适用于 Javascript 的 html 输出