0

I have a div containing a background image that I want to keep aligned in the bottom right corner but I want the image to scale depending on the size of the browser window. What I currently have is:

backgnd {
    background: url(img/roneggler.png) no-repeat;
    position: fixed;
    bottom: 0px;
    right: 0px;
    width: 1000px;
    height: 1000px;
}

I have tried to set the width and height values to 100% but that messes with the position of the div. The link of this page can be found here: http://inetgate.biz/ron.eggler/

3 Answers 3

1

You should use background-size: cover and width and height 100%;

backgnd {
    background: url(img/roneggler.png) no-repeat;
    position: absolute;
    background-size: cover;
    bottom: 0px;
    right: 0px;
    width: 100%;
    height: 100%;
}
Sign up to request clarification or add additional context in comments.

4 Comments

If I use what you suggest, the image isn't bottom aligned.
Try using position aboslute (instead of fixed ) ..and eventually set the proper bottom right position
Yeah, I'm using absolute as you suggested above. It looks like the div scales nicely but the background image doesn't stay aligned absolute to the bottom right corner of the div. I added a temporary border: 5px solid red; to the div to better depict things
you should post a link to jsfiddle for or codepen for see the page and the code ..
0

CSS:

.container{
  width:100%;
}

you can use jQuery:

var w = $(window).width();
$('.content').css('width', w);

Comments

0

Okay,

I got it now, the final solution looks like:

.backgnd {
    background: url(img/roneggler.png) no-repeat;
    background-size: contain;
    background-position: right bottom;
    position: absolute;
    bottom: 0px;
    right: 0px;
    width: 100%;
    height: 100%;
}

The trick was t use background-size: contain; instead of cover to not get the image to scale up all the way on big screens.

Comments

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.