0

I have a div container on which i have placed two more div's (say 1 & 2) for placing the content . I have set different ids for the div's and on clicking the link( of div 2) i am changing the background image of the background div. I am trying to set the background-size as cover to occupy the whole screen width but only the upper part of the image is getting displayed. Here is the code which i am using to set the background size for the div.

     <script>
    $(document).ready(function(){
        //autoOpen: false,
        $(".span12").css('background-image','url(../images/assorting_2.jpg)','background-size','100%');
<script>

I could have posted the images but i am unable to post it as i have less points.

5
  • 1
    CSS background-size: cover; css-tricks.com/perfect-full-page-background-image Commented Dec 7, 2013 at 6:46
  • get your full code on jsfiddle.net Commented Dec 7, 2013 at 6:46
  • 1
    You need to pass an object to the css method for multiple styles Commented Dec 7, 2013 at 6:47
  • You got three answers now select the most helpful one by clicking on the mark under the votes. Commented Dec 7, 2013 at 7:08
  • Didn't one of the answers work? Commented Dec 7, 2013 at 9:27

2 Answers 2

3

Try this:

$(".span12").css({
    'background-image':'url(../images/assorting_2.jpg) no-repeat',
    'background-size':'cover'
});

See this for using multiple jQuery CSS properties. And this for using background cover.

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

Comments

1

Try like

$(".span12").css({
                   'background-image':'url(../images/assorting_2.jpg) no-repeat',
                   'background-size':'100%'
                 });

Comments

Your Answer

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