Changing HTML button tag background color with css?

Meta

I am using the HTML button tag for my submit buttons as well as buttons that direct to other pages and features I would like to be able to have buttons with different backgrounds (one blue, one grey, one red, one green, etc) but can't seem to get it working by simply adding a class tot he button tag.

Here is what I have so far HTML

<button class="green_btn" type="submit" name="cnp">News Control</button>

CSS

button {
    margin: 0 auto 5px auto;
    display: block;
    width: 134px;
    height: 35px;
    background: url('../images/darkgrey_btn_bg.png') no-repeat left;
    border: 0 none;
    font-weight: bold;
    text-align: center;
    color: #fff;
    cursor: pointer;
}
.grey_btn button {
    background: url('../images/darkgrey_btn_bg.png') no-repeat left;
}
.green_btn button  {
    background: url('../images/green_btn_bg.png') no-repeat left;
}
.ltblue_btn button {
    background: url('../images/ltblue_btn_bg.png') no-repeat left;
}
.blue_btn button {
    background: url('../images/blue_btn_bg.png') no-repeat left;
}
.red_btn button {
    background: url('../images/red_btn_bg.png') no-repeat left;
}

by default I want the button to be the garkgrey_btn_bg.png as the background, but if I want to use the green_btn_bg.png for the background, adding class="green_btn" to the html does nothing.

Anyone have any ideas?

Seth

You're targeting your class improperly with .class-name button. That is actually looking for an element with a child button.

Here you go...

button.grey_btn {
    background: url('../images/darkgrey_btn_bg.png') no-repeat left;
}
button.green_btn  {
    background: url('../images/green_btn_bg.png') no-repeat left;
}
button.ltblue_btn {
    background: url('../images/ltblue_btn_bg.png') no-repeat left;
}
button.blue_btn {
    background: url('../images/blue_btn_bg.png') no-repeat left;
}
button.red_btn {
    background: url('../images/red_btn_bg.png') no-repeat left;
}

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Radio button not changing background color HTML/CSS

From Dev

Changing background color of button with inline CSS

From Dev

HTML background color not changing

From Dev

HTML5 Changing paragraphs background color with button js

From Dev

Android Button background color not changing

From Dev

Changing the background color of a Button in Kivy

From Dev

Changing background color in wordpress with a button

From Dev

background color not changing on hover css

From Dev

background color not changing on hover css

From Dev

CSS changing (transitioning) background color

From Dev

Changing the border color of a submit button after clicking it, CSS, HTML

From Dev

Changing the border color of a submit button after clicking it, CSS, HTML

From Dev

Changing background color of a button when clicked

From Dev

<input type=button /> Changing Background color

From Dev

HTML, CSS - background image not changing

From Dev

Changing background color on input focus with css alone

From Dev

changing css background color with javascript variables

From Dev

Automatic changing background color loop (jQuery/css?)

From Dev

changing css background color with javascript variables

From Dev

changing css background-color property

From Dev

Background color is not changing after adding CSS

From Dev

Automatic changing background color loop (jQuery/css?)

From Dev

CSS list menu is not changing background-color

From Dev

Changing background color based on browser size in CSS

From Dev

Changing HTML button font with CSS

From Dev

Javascript not changing html background color persistenly

From Dev

Changing the background color in html5

From Dev

HTML CSS: Switch/Change background color of div, color of label text on radio button selection

From Dev

background-color fills another tag | CSS

Related Related

  1. 1

    Radio button not changing background color HTML/CSS

  2. 2

    Changing background color of button with inline CSS

  3. 3

    HTML background color not changing

  4. 4

    HTML5 Changing paragraphs background color with button js

  5. 5

    Android Button background color not changing

  6. 6

    Changing the background color of a Button in Kivy

  7. 7

    Changing background color in wordpress with a button

  8. 8

    background color not changing on hover css

  9. 9

    background color not changing on hover css

  10. 10

    CSS changing (transitioning) background color

  11. 11

    Changing the border color of a submit button after clicking it, CSS, HTML

  12. 12

    Changing the border color of a submit button after clicking it, CSS, HTML

  13. 13

    Changing background color of a button when clicked

  14. 14

    <input type=button /> Changing Background color

  15. 15

    HTML, CSS - background image not changing

  16. 16

    Changing background color on input focus with css alone

  17. 17

    changing css background color with javascript variables

  18. 18

    Automatic changing background color loop (jQuery/css?)

  19. 19

    changing css background color with javascript variables

  20. 20

    changing css background-color property

  21. 21

    Background color is not changing after adding CSS

  22. 22

    Automatic changing background color loop (jQuery/css?)

  23. 23

    CSS list menu is not changing background-color

  24. 24

    Changing background color based on browser size in CSS

  25. 25

    Changing HTML button font with CSS

  26. 26

    Javascript not changing html background color persistenly

  27. 27

    Changing the background color in html5

  28. 28

    HTML CSS: Switch/Change background color of div, color of label text on radio button selection

  29. 29

    background-color fills another tag | CSS

HotTag

Archive