想要覆盖 Bootstrap,但如何避免使用 !important?

编程入门 行业动态 更新时间:2024-10-28 08:27:14
本文介绍了想要覆盖 Bootstrap,但如何避免使用 !important?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

限时送ChatGPT账号..

我正在使用 Bootstrap 并想覆盖一些 css:我正在删除处于禁用状态时表单字段中的背景、边框和不允许的指针.

I am using Bootstrap and want to override some css: I am removing the background, border and the not-allowed-pointer in form fields when in disabled state.

这是我的 css 的样子:

This is how my css looks:

.no-extras {
  border: 0 !important;
  box-shadow: none !important;
  background-color: white !important;
  cursor: default !important;
}

但我知道使用 !important 是一件坏事.但是我应该如何更改代码以避免使用 !important?我试图用input.no-extras"和类似的东西使它更具体,但到目前为止还没有任何运气......

But I know it is a bad thing to use !important. But how should I change the code to avoid using !important? I have tried to make it more specific, with "input.no-extras" and similar, but have not had any luck so far...

在此处查看示例代码http://plnkr.co/edit/1AuszJ?p=preview

See example code here http://plnkr.co/edit/1AuszJ?p=preview

推荐答案

您可以简单地通过更具体的选择器来覆盖 CSS.以更具体的方式选择相同标签的任何内容都足以覆盖现有定义.因此,例如,在目标类之前放置一个 form 引用就足够了:

You can override CSS simply by being more specific with your selectors. Anything that selects the same tag in a more specific way is enough to override an existing definition. So, for example, putting a form reference before the target class is enough:

form .form-control[disabled] {
  cursor: default;
}  

Plunker 演示

这篇关于想要覆盖 Bootstrap,但如何避免使用 !important?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

更多推荐

[db:关键词]

本文发布于:2023-04-29 14:25:17,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1191456.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:Bootstrap   important

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!