Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7853255
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T19:37:45+00:00 2026-06-02T19:37:45+00:00

I’ve been working for some time on my first website. I have the CSS

  • 0

I’ve been working for some time on my first website. I have the CSS working but I still need to fix some simple, but no so simply issues. In the index.html file I have a background picture attached to the html. So I have a fullscreen background picture attached via CSS to the html tag. This is the CSS code:

html{   background: no-repeat center center fixed; 
-webkit-background-size: cover;     -moz-background-size: cover;
-o-background-size: cover;  -ms-background-size: cover;
background-size: cover; }

But I’m loading the pictures via Javascript. My objective is to have an array of pictures and each time a user loads the website or triggers it a random picture will be displayed. So I have this code in Javascript which is working:

$(document).ready(function()  {
  var randomImages = ['img1','img2','img3','img4','img5'];
   var rndNum = Math.floor(Math.random() * randomImages.length);
   $("html").css({
      background: "url(_img/bg/index_rnd/" + randomImages[rndNum] + ".jpg)
      no-repeat"
    });
});

All these codes are working. The pictures are selected from an array and displayed randomly once they are loaded. But I have a great problem which I cannot find a clear answer and I’m stuck. I would like that the width and the height are rezised, so the whole picture is displayed in the screen. Of course each screen is different… I read something about innerhieght and innerwidth properties, but I do not know how to proceed. What should I do so the pictures resize to each different screen?

In this moment the pictures are with a resolution of 1024×683. I have a computer with a screen of 15″” and a resolution of 1440×900. My pictures get always a bit more pixelated and to long in height to display, so a part of the picture is cut.

Questions:

What should I do so the pictures resize to each different screen resolution?

A recommended picture resolution so the picture is displayed correctly?

Is there a way to display the picture into the exact size of a screen? Even if its original format gets a bit modified?

REPLY AFTER RECIEVING ANSWER ————————————————————-
NEW QUESTION —————————————————————————–

Hello, at last I had time to use the code… It does work properly. I only needed to add the url to my image folder and magic!!! So my code is actually like this:

$(window).load(function() {
    var randomImages = ['img1','img2','img3','img4','img5'];
    var rndNum = Math.floor(Math.random() * randomImages.length);

     var $win = $(this);
     var $img = $('#background').attr('src', '_img/bg/index_rnd/' + randomImages[rndNum] + '.jpg').css({'position':'fixed','top':0,'left':0});
        function resize() {
            if (($win.width() / $win.height()) < ($img.width() / $img.height())) {
              $img.css({'height':'100%','width':'auto'});
            } else {
              $img.css({'width':'100%','height':'auto'});
            }
        }
        $win.resize(function() { resize(); }).trigger('resize');
    });

Regarding my html I have for now an image with id background. I want to center the image as told. So my question is if I should put this image in a div. If so, how can I make this image center itself in the center of the screen???

Another question, before I had my image attachted to the html and now to an image. Therefore the image is influencing other elements I have in my body. How can I make that this image be displayed behind all the other elements of my body?!?! For example my logo and header_bg are transformed when my img id=”background” is loaded.

Can you help???

This is my html for any doubts…

<body>
        <img id="background" src="" alt="" />
        <div id="header_img">
            <nav>
                <div id="header-bg-left">
                    <div id="nav-content">
                        <div id="logo">
                                <a href="index.html"><img alt="./_img/nav/logo.rosa.png" src="">logo</a>
                        </div>
                        <div id="categories">       
                                <ul>
                                    <li id="nav-quien"><a href="#">quien es</a>
                                        <ul>
                                            <li id="nav-biografia" class="drop1"><a href="biografia.html">biografia</a></li>
                                            <li id="nav-curriculum" class="drop2"><a href="curriculum.html">curriculum</a></li>
                                        </ul>
                                    </li>
                                    <li id="nav-galeria" class="marginli"><a href="gallery.html">galeria</a>
                                        <ul>
                                            <li id="nav-gal-nat" class="drop3"><a href="gallery.html">paisaje natural</a></li>
                                            <li id="nav-gal-urb" class="drop4"><a href="gallery.html">paisaje urbano</a></li>
                                        </ul>
                                    </li>
                                    <li id="nav-prensa" class="marginli"><a href="prensa.html">prensa</a></li>
                                    <li id="nav-links" class="marginli"><a href="links.html">links</a></li>
                                    <li id="nav-contacto" class="marginli"><a href="contacto.html">contacto</a></li>
                                </ul>
                        </div>
                    </div>
                </div>
            </nav>
        </div>
        <footer>    
            <div id="footer-bg-left">
                <div id="foot-content">
                    <p>Diseñado por <a href="mailto:daniramirezescudero@gmail.com">Daniel. R-Escudero</a> <span>|</span> Todos los derechos reservados <span>|</span> <a href="mailto:info@scalesplanet.com">info@rosasusaeta.com</a> <span>|</span><a href="http://www.linkedin.com/"><img src="./_img/footer/logo.linked.png"></a> <a href="http://www.facebook.com/"><img src="./_img/footer/logo.facebook.png"></a></p>
                </div>
            </div>  
        </footer>
    </body>
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-02T19:37:46+00:00Added an answer on June 2, 2026 at 7:37 pm

    UPDATED 29 Nov 2012

    • demo: http://so.devilmaycode.it/height-and-width-of-background-picture-adapt-to-each-screen-size/
            $(window).resize(function() {
                resize();
            });
            $(function() {
                $('#background').attr('src', 'http://cdn.com/bg.png').css({
                    'position' : 'fixed',
                    'top' : 0,
                    'left' : 0
                });
                resize();             
            });
            function resize() {
                var $img = $('#background');
                if (($(window).width() / $(window).height()) < ($img.width() / $img.height())) {
                    $img.css({
                        'height' : '100%',
                        'width' : 'auto'
                    });
                } else {
                    $img.css({
                        'width' : 'auto',
                        'height' : $(window).height() + 'px'
                    });
                }
            }
    
    <body>
      <img id="background" src="" alt=""/>
    </body>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have just tried to save a simple *.rtf file with some websites and
I have a jquery bug and I've been looking for hours now, I can't
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I have a French site that I want to parse, but am running into
I need to clean up various Word 'smart' characters in user input, including but
Seemingly simple, but I cannot find anything relevant on the web. What is the
I have thousands of HTML files to process using Groovy/Java and I need to
I'm making a simple page using Google Maps API 3. My first. One marker
I have some data like this: 1 2 3 4 5 9 2 6
link Im having trouble converting the html entites into html characters, (&# 8217;) i

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.