Why does Twitter Bootstrap require multiple classes for buttons?

后端 未结 2 1642
广开言路
广开言路 2021-01-21 05:05

To make a primary button using Twitter\'s Bootstrap library, you need to use two CSS classes like so: class=\"btn btn-primary\".

Why did they design the API

相关标签:
2条回答
  • 2021-01-21 05:45

    Because btn-primary isn't the default button. It's additional CSS that turns it blue much like btn-success turns it green.

    The default button is grey.

    0 讨论(0)
  • 2021-01-21 05:54

    This is because of OOCSS principles. Detaching certain styles from elements allows for better code and style reuse and a easier way to rapidly modify any object in your css. For example, you have your main .btn class that styles your button with the default grey color, so all buttons with the .btn class will have the same style, but with predefined styles you can extend that same button class to support multiple different color schemes without the need to write the default .btn properties over and over again, so its easier to maintain. If you look at the css for the .btn-warning and all other button state classes you can see that they just define the color and style of the button and skip the need to rewrite the button class once again;

    .btn-warning:hover, .btn-warning:active, .btn-warning.active, .btn-warning.disabled, .btn-warning[disabled] {
        background-color: #F89406;
    }
    

    This allows for easier to read and shorter,more cleaner stylesheets.

    0 讨论(0)
提交回复
热议问题