bootstrap button on click showing default colour

前端 未结 7 551
广开言路
广开言路 2021-01-31 08:13

I am trying to style the button colour with below code, the colours work until I click the button, the button shows the default colours, how do I specify the colours of the butt

7条回答
  •  北恋
    北恋 (楼主)
    2021-01-31 09:05

    If you are working on a personal project, and not with a team, it is worth noting that you can override pseudo class styles simply by applying "!important" to the same style declarations on the class:

    .btn-success { color: #ffffff !important; background-color: #161617 !important; border-color: #494F57 !important; }

    Generally, it's a good idea to stay away from !important because this will override any and all color, background-color and border-color style declarations on the btn-success class (unless you override the style declarations again with !important later in your style sheet although that's ridiculous).

    If the goal is the smallest file size possible though and you are using this class everywhere in the same way - meaning no inline styles - then this may be your best option.

    Alternatively, but using the same thinking, you may try naming a new custom class something like .btn-success-important, and only apply it after btn-success where you need to use the override.

    There is one catch though: If you are combining .btn-success or your .btn-success-important with any other Bootstrap .btn-group, !important will override any pseudo class style declared within. In this case you may be better off with Guy's answer (the custom class without !important style declarations).

提交回复
热议问题