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 6165531
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T22:10:56+00:00 2026-05-23T22:10:56+00:00

The previous question I asked about creating a DIV where size is calculated from

  • 0

The previous question I asked about creating a DIV where size is calculated from height x width of viewport is answered very well here: Square DIV where height is equal to viewport

I have a background image applied to the #square DIV that fits and resizes beautifully when JavaScript is on. However when JavaScript is OFF, the background image stretches to a width of 100% of the viewport- I presume because the #square div isn’t being fed any information about how wide it should be, and is defaulting to 100%.

So my question is: what approaches could I use so that this doesn’t happen? Can I feed my #square DIV a default-width in case JavaScript is OFF, but which is overridden when JavaScript is ON?

Here is the JQuery (thanks to the answer on the previous question):

$(document).ready(function(){
    var height = $(window).height();
    $('#square').css('height', height);
    $('#square').css('width', (height*1.1));
});

Here is the CSS:

html, body, img {
    height: 100%;
    margin: 0;
    border: 0;
    padding: 0;
}

#container {
    width: 100%;
    height: 100%;
    min-width: 500px;
    min-height: 500px;
    background-color: #e0aa0e;
}

#square {
    min-width: 500px;
    min-height: 500px;
    overflow: hidden;
    background-image:url('images/bg.png');
    background-repeat: no-repeat;
    background-size:cover;
}

and here is the HTML:

<div id="container">
    <div id="square">
        Content within square
    </div>
</div>

What I am trying to do is create a liquid, resizable page with information elements arranged over different regions of the background image of #square- so I am basing all element sizing off the size of #square. Which, since #square is getting it’s sizing from JQuery, doesn’t work with JavaScript off. Am happy for the no-JQuery view to be static rather than liquid. Thanks in advance for all suggestions.

  • 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-05-23T22:10:57+00:00Added an answer on May 23, 2026 at 10:10 pm

    You could put a CSS class on the #square div which has an absolute width and height set, and then in your jQuery script, use removeClass() on #square to remove that CSS class. Thus with no jQuery available, it’d be that set width and height, and then if jQuery is enabled, it becomes liquid.

    #square {
        min-width: 500px;
        min-height: 500px;
        overflow: hidden;
        background-image:url('images/bg.png');
        background-repeat: no-repeat;
        background-size:cover;
    }
    
    #square.nojavascript {
        width: 960px;
        height: 960px;
    }
    

    <div id="square" class="nojavascript">
    

    $('#square').removeClass('nojavascript');
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This stems from a previous question I asked - about a write conflict with
So in a previous question I asked about implementing a generic interface with a
In a previous question I asked about how to group XML elements logically, and
This is a follow up question to a previous question I asked about calculating
In a previous question, I asked about various ORM libraries. It turns out Kohana
Unit testing Abstract classes in Groovy I asked a question previous about unit testing
this question is an extension to a previous question i asked (and was answered).
This is a continuation question from a previous question I have asked I now
In my previous question I asked about storing the result of a query in
This question is in continuation to my previous question, in which I asked about

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.