tags:

views:

63

answers:

4

I am trying to create a button using CSS Gradients plus a icon that goes on top of the gradient. I tried 2 ways and both was a failure.

First:

.btn {
    background: -webkit-gradient(linear, 0% 0%, 0% 89%, from(#3171CA), to(#15396F));
    background: url(../images/btn.png);
}

I should of knew that wouldn't of worked! But I also heard about CSS3 multiple background images, so I tried it that way.

Second:

.btn {
        background: -webkit-gradient(linear, 0% 0%, 0% 89%, from(#3171CA), to(#15396F)), url(../images/btn.png);
    }

Still didn't work :(. Is there any way to actually do this? With adding a <img> tag in the <button>?

A: 

You should use your first example, but reverse the lines so that the image is applied before the gradient. All browsers will get a background image, but only browsers that understand -webkit-gradient will use the gradient. All others will ignore it.

.btn {
  background: url(…);
  background: -webkit-gradient(…);
}
Todd Yandell
I am trying to use both gradient and image on the button. This doesn't work..
omnix
Ah, sorry. Should have read your question more carefully.
Todd Yandell
A: 

You could flatten your icon onto a gradient background meaning you'd only need to set the background-image. Other than that, I think you're going to have to put an tag (or a container with the image as background) inside your gradient-ified container.

soutarm
+4  A: 

only webkit browsers allow multiple background effects (CSS3) .. generally speaking you can have a gradient OR and image but you can't have both (yet)

you could overlay 2 divs tho and have the image for the topmost be transparent PNG or such

Scott Evernden
like <span><button> Hello </button> </span> then in css have the <span> background with a png and button with the gradients? would that work?
omnix
yeah or just <div><div></div></div> - css can em all work ..
Scott Evernden
A: 

I think it'd be better and more compatible if you just put the gradient and button together in the same image, but if it's not practical in your situation, you can achieve the same effect using multiple divs:

<div style="width:256px; height:256px; background:-webkit-gradient(linear, 0% 0%, 0% 89%, from(#3171CA), to(#15396F));">
<div style="width:100%; height:100%; background:url('btn.png') "></div></div>

Make sure you change the width/height parameters I set if you use mine.

Kranu