1

I have DIV which has 2 backgrounds, in my case, it is gradient and image. I want to change the size of the background image, but not the size of the gradient ? Is it possible ?

Please note: I don't want to use 2 DIVs, one for gradient and one for background image

EDIT:

<div id="button"></div>

#button { background: url(img.png) no-repeat 0.5em 0.5em, -webkit-gradient(linear, left top, left bottom, from(#74ae0f), to(#497105)); }
2
  • Can you show your current markup? Commented May 3, 2011 at 11:10
  • OK, I've added the mark up, it's pretty simple. Just DIV and CSS which sets multiple backgrounds - the first background is image and the second background is gradient. I want to set specific background size just for the first background image. Commented May 3, 2011 at 11:57

2 Answers 2

2

Ok, by just simple coincidence I have found answer to my question. I couldn't find it anywhere on the internet, so I just tried this and it worked as I wanted:

background-size: 2em 2em, 100% 100%;

The first declaration "2em 2em" applies to background image and the second declaration "100% 100%" applies to background gradient. Therefore using the same order as both backgrounds were declared in background definition.

Now it seems simple and straightforward, but I didn't find it in any documentation or webpage.

Sign up to request clarification or add additional context in comments.

Comments

1

i think you can just add

-o-background-size: 80%, 30%; 
-webkit-background-size: 80%, 30%;    
-moz-background-size: 80%, 30%;
background-size: 80%, 30%;

1 Comment

Sure I can, but this would change the size of BOTH background image and background gradient, which is exactly what I do NOT want... I need to set only the size of the background image, NOT background gradient.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.