Why is there an important override on the border classes's color property in Bootstrap?

陌路散爱 提交于 2019-12-20 07:42:51

问题


When applying a border to my navigation, I thought it would be best practice to make use of the Bootstrap .border class.

But looking into the code that will render using this class, it appears to be using an !important value on the color value of the border property inside the .border class. In this case I was making use of the .border-bottom class to add a border to the bottom of my navigation.

This is what the rendered code would look like when using the class:

.border-bottom {
    border-bottom: 1px solid #dee2e6!important;
}

This means if I want to edit the color of this border class, I am required to override the color value with another !important value. I was wondering, why is this done like this?

Should I still use the .border class for achieving this purpose and override using another !important in a custom stylehsheet? Or is the .border class not meant for achieving the purpose I am trying to achieve (e.g. I would like a red border instead of whatever white/grey-ish color this is)?


回答1:


Using !important is considered to be acceptable for utility/helper classes, and Bootstrap's authors have chosen to use !important on all of the Bootstrap 4 Utility classes.

This means that the Border Color utility classes also use !important, and since they follow the other Border classes in CSS file, the !important on the color will take precedence (Example).

If you want to define your own custom border color, then as you said, you will need to use !important.




回答2:


You are probably using it right, but to change the value of that you probably need to do it in the variable sass file in bootstrap.



来源:https://stackoverflow.com/questions/49479632/why-is-there-an-important-override-on-the-border-classess-color-property-in-boo

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!