0

Two buttons are dynamically generated (they're out of my control). I would like to change the images of these buttons but I'll have to use CSS since I can't actually change the button code. I'm assuming I'll need to do this based on the CSS values if that's even possible. Here's the button code:

<button type="submit" class="btn btn-default" name="provider" value="Facebook" title="Log in using your Facebook account.">Facebook</button>

<button type="submit" class="btn btn-default" name="provider" value="Twitter" title="Log in using your Twitter account.">Twitter</button>

The two images that I wish to implement are: Facebook-Login.png and Twitter-Login.png. If this is possible with CSS can someone please post the code? Thanks, Chris.

DigitalRayne
  • 389
  • 2
  • 3
  • 14

3 Answers3

4

You can use this awesome attribute selector

Read more about it here: http://css-tricks.com/attribute-selectors/

CSS

.btn-default[value="Facebook"] {
    background: url("Facebook-Login.png");
}

.btn-default[value="Twitter"] {
    background: url("Twitter-Login.png");
}

you might need to use background instead of background-image due to the fact that button uses background by default for gradient in most browsers. You also will want to check on mobile browsers like safari - and may need to use -webkit-appearance: none; to remove default styling... and maybe even border-radius: 0; to remove rounded corners.

Community
  • 1
  • 1
sheriffderek
  • 8,848
  • 6
  • 43
  • 70
1

Yes, possible with css. Use the following:

.btn-default[value="Facebook"]{
    background:url("Facebook-Login.png");
    color: transparent; 
    width: 100px;
    height: 100px;
    line-height: 0; 
    font-size: 0; 
}

.btn-default[value="Twitter"]{
    background:url("Twitter-Login.png");
    color: transparent; 
    width:100px;
    height:100px;
    line-height: 0; 
    font-size: 0; 
}

You will need a css selector with the button and value set properly. Since you have text in the button, you will probably want to hide the text, so set color:transparent to hide the text but not the image.

You will have to change the width and height to the correct pixel amount.

Sources:

how do i hide anchor text without hiding the anchor

http://www.w3schools.com/cssref/sel_attribute_value.asp

Good luck

Community
  • 1
  • 1
js_gandalf
  • 881
  • 8
  • 18
  • Awesome! :) Such a simple solution and I've been stressing for this for hours. It's always the simple things that cause the most problems. This solution worked the best by hiding the anchor text but it should be noted that I needed .btn-default and not "button" in the css. But for the general knowledgebase this was awesome. Thanks :) – DigitalRayne Mar 02 '14 at 06:13
  • Oops, your right. I'll make the change just to keep things consistent. – js_gandalf Mar 02 '14 at 06:16
0

The js and seri answer is very based . this code is smart code . I give them a hover menu image code . just see it .

.batton{background: #00F;}

.batton:hover{background:url("Twitter-Login.png");}