为您的 less 文件添加额外的颜色并重新编译。另见Twitter Bootstrap Customization Best Practices。
更新
正如@ow3n 提到的,自 v3.0.3 以来使用:
.btn-custom {
.button-variant(@btn-default-color; @btn-default-bg; @btn-default-border);
}
注意上面@btn-default-color设置字体颜色,@btn-default-bg设置背景颜色,@btn-default-border设置边框颜色。根据这些参数计算活动、悬停和禁用等状态的颜色。
例如:
.btn-custom {
.button-variant(blue; red; green);
}
将导致:
想要直接使用 CSS 的,请替换这段代码中的颜色:
.btn-custom {
color: #0000ff;
background-color: #ff0000;
border-color: #008000;
}
.btn-custom:hover,
.btn-custom:focus,
.btn-custom:active,
.btn-custom.active,
.open .dropdown-toggle.btn-custom {
color: #0000ff;
background-color: #d60000;
border-color: #004300;
}
.btn-custom:active,
.btn-custom.active,
.open .dropdown-toggle.btn-custom {
background-image: none;
}
.btn-custom.disabled,
.btn-custom[disabled],
fieldset[disabled] .btn-custom,
.btn-custom.disabled:hover,
.btn-custom[disabled]:hover,
fieldset[disabled] .btn-custom:hover,
.btn-custom.disabled:focus,
.btn-custom[disabled]:focus,
fieldset[disabled] .btn-custom:focus,
.btn-custom.disabled:active,
.btn-custom[disabled]:active,
fieldset[disabled] .btn-custom:active,
.btn-custom.disabled.active,
.btn-custom[disabled].active,
fieldset[disabled] .btn-custom.active {
background-color: #ff0000;
border-color: #008000;
}
.btn-custom .badge {
color: #ff0000;
background-color: #0000ff;
}
结束更新
要生成自定义按钮:
.btn-custom {
.btn-pseudo-states(@yourColor, @yourColorDarker);
}
上面会生成如下的css:
.btn-custom {
background-color: #1dcc00;
border-color: #1dcc00;
}
.btn-custom:hover,
.btn-custom:focus,
.btn-custom:active,
.btn-custom.active {
background-color: #19b300;
border-color: #169900;
}
.btn-custom.disabled:hover,
.btn-custom.disabled:focus,
.btn-custom.disabled:active,
.btn-custom.disabled.active,
.btn-custom[disabled]:hover,
.btn-custom[disabled]:focus,
.btn-custom[disabled]:active,
.btn-custom[disabled].active,
fieldset[disabled] .btn-custom:hover,
fieldset[disabled] .btn-custom:focus,
fieldset[disabled] .btn-custom:active,
fieldset[disabled] .btn-custom.active {
background-color: #1dcc00;
border-color: #1dcc00;
}
在上面的#1dcc00 将是您的自定义颜色,#19b300 将是您较深的颜色。除了较少的解决方案,您还可以将此 css 直接添加到您的 html 文件中(在引导 css 之后)。
或者直接从Twitter's Bootstrap 3 Button Generator获取你的css代码