2

In this forum i read that i need to use JQ to resize background-image. but i don't know JQ and want to resize background-image by css3. Can i do it? If possible show me the right direction, please.

I have two background images. One - texture with repeat (i don't want to scale it), And another one - below - whole picture (this one i don't want to repeat and want to resize when site change resolution (for ex on small screens).

    body { 
     padding-top: 60px; 
     padding-bottom: 40px;
     background-color:#ededed;
     background-image:url('http://b.pusku.com/wp-content/uploads/2012/11/textura5.png'), url('http://b.pusku.com/wp-content/uploads/2012/11/fone1.jpg'); 
} 
6
  • Possible duplicate stackoverflow.com/questions/10991216/… Commented Jan 18, 2013 at 14:35
  • 1
    Also this stackoverflow.com/questions/5867908/… Commented Jan 18, 2013 at 14:36
  • thank you! but i cant understand how i can select only one image in code. these examples have only one image Commented Jan 18, 2013 at 14:38
  • give the image a class and style it that way. <img class="classname" > and in your css, put .classname { /* styles for the image here */ } Commented Jan 18, 2013 at 14:40
  • 1
    The second link is for two background images, ie something like background-size: 2em 2em, 100% 100%; Commented Jan 18, 2013 at 14:44

1 Answer 1

3

Here is an example. The 40% 20% section is the size for the first image, the 20% 15% is for the second image. The repeat rules then specify that the first image doesn't repeat and the second does.

 body { 
     padding-top: 60px; 
     padding-bottom: 40px;
     background-color:#ededed;
     background-image:url('http://upload.wikimedia.org/wikipedia/commons/c/cb/Fighting_kittens-1340.jpg'), url('http://thepersiankittens.com/Persian_Kittens.jpg'); 
     height: 1000px;
     width: 400px;
     background-size: 40% 20%, 20% 15%;
      background-repeat: no-repeat, repeat;
    }

Here is an example that you can play around with http://jsbin.com/ojudel/1/edit

Change the percentages and you will see how it works. More information can be found here.

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

3 Comments

Thank you very for all answers! I tried all examples and in my case this - 2em 2em, 100% 100% - working good! I see that i need to learn more about this css3 rules and i will play with jsbin more. Only one things i couldnt do - save proportions for background pic in my fluid layout.
@Lucky You should be able to get it to work one way or another, using auto as a size, but then responsive bit is another thing entirely :)
Mookamafoob, thank you very much for answers! I will play with auto in my fluid layout:)

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.