Using Bootstrap to Change Button Color
Asked Answered
G

3

6

I'm using RoR to make a one-month rails website. This is the code from the styles.css.scss sheet. It utilizes bootstrap. I am unsure as to why but the button color does not change despite the $btnPrimaryBackground: green text. Does anyone have any ideas or thoughts on why the button color doesn't change? Thanks.

$baseFontFamily: Oxygen;
@import url(http://fonts.googleapis.com/css?family=Oxygen);


$navbarBackgroundHighlight: white;
$navbarBackground: white;
$btnPrimaryBackground: green;

@import 'bootstrap';
body{
    padding-top: 60px;
}

@import 'bootstrap-responsive';

.navbar-inner{
    @include box-shadow(none !important);
    border: 0;
}

.footer{
    margin-top: 50px;
    color: $grayLight;
    a{
        color: $gray;
    }
}
Glenda answered 31/7, 2013 at 0:37 Comment(0)
P
5

If you are using Bootsrap with LESS, you can simply do:

.btn-primary {
  .buttonBackground(@yourColor, @yourColorDarker); //(button, hover)
}

If not then you simply override the button class which you want to change color:

.btn-warning { background-color: Your color; } //button

.btn-warning:hover { background-color: Your color; } //hover

Furthermore, since it appears you want to change the button color to green why dont you use the .btn-success class like so:

<%= button_tag "Hello", :class => "btn btn-success" %>

Source: Styling twitter bootstrap buttons

Parasynthesis answered 31/7, 2013 at 1:27 Comment(8)
I apologize- how would I implement this code? I am a beginnerGlenda
Sincerest apologies - I'm not sure how to implement that into the code I posted...Glenda
Well, you just have to paste the button_tag code in whatever view you want it to be.Parasynthesis
Also what is the difference bw the button code you gave and the one I used (i.e. one is class:, while the other is :class)? Thanks again!Glenda
I don't see where you used class: but anyways it is a basically two different ways to give a symbol a value. The one is used uses the hashrocket syntax which is :symbol => value while the one you mentioned simply uses this syntax symbol: value. Anyways, if my post helped you don't forget to mark it as the answer. Good luck!Parasynthesis
I'm not sure what happened, but I just re-typed my original code and the button is showing up green now! Although, trying out your suggestions did the same effect and helped me get a better feel for how to change up some of the settings.Glenda
That's strange... Anyways, I'm glad I could help.Parasynthesis
One thing important - also add change the .border-color attribute, or the button keeps it's original border color.Schafer
S
2

In Bootstrap 3 buttonBackground doesn't work anymore, you have to use button-variant(@color; @background; @border) like this:

.btn-custom {
    .button-variant(@custom-color, @custom-color-bg, @custom-color-border);
}
Smog answered 28/5, 2014 at 11:14 Comment(0)
T
0

You can also make your own and inherit from .btn-default. In SCSS like this:

.btn-custom { @extend .btn; @extend .btn-default; color: #6EA81A; }

Tactical answered 23/3, 2015 at 18:44 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.