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

  • Home
  • SEARCH
  • 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 6621647
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T21:17:39+00:00 2026-05-25T21:17:39+00:00

Sorry but I can’t get this to work. Should be a quick answer. My

  • 0

Sorry but I can’t get this to work. Should be a quick answer.

My html is laid out like so:

<html>
    <header> 
    ... 
    </header>

    <body> 
        <div class = "background"></div>
        <div class = "content">
        ...
        </div>
    <body>
</html>

The I want the background div to simply place a 1000px background colour down the entire length of the page. The content is then padded 40px on each side, inside this background colour.

The css is like so:

body {
    width:1000px;
    margin-left:auto;
    margin-right:auto;
}

.background {
    position:absolute;
    top:0px;
    width:1000px;
    height:100%;
}

.content {
    min-height:100%;
    padding-left:40px;
    padding-right:40px;
}

I thought it worked like so… The body div would expand to hold the min-height of the .content div. This means that 100% height of the .background div would fill the entire body and so the length of the page. However it does not. It only fills the window height. Where am I going wrong?

Thanks

  • 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-25T21:17:39+00:00Added an answer on May 25, 2026 at 9:17 pm

    As topek guessed, this will do it:

    html, body{
      height:100%
    }
    

    The reason this works is because percentage CSS heights only work if the parent element has a height defined on it. By adding the above, you’re giving .background‘s parents a height.

    Update: based on OP’s comment, here’s how you would get the .background div to always appear to fill the viewport:

    html, body {
       height: 100%;
       padding: 0;
       margin: 0;   
    }
    
    /* Fixed element that takes up entire viewport */
    .background {
       position: fixed;
       z-index: 1;
       top: 0;
       left: 0;    
    
       width: 100%;
       height: 100%; 
    }
    
    /* Content that stacks above .background */
    .content {
       position: relative;
       z-index: 2;
    }
    

    As .content grows larger than the viewport and the user scrolls, the fixed position of .background will keep it always in view.

    And of course, a handy example.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Sorry if this question is very easy, but I can't find the answer anywhere.
Sorry, I'm sure this is simple but I'm tired and can't figure it out.
I'm sorry if this is too obvious but I can't find any proper answer
Sorry if this seems like a stupid question but can't find any info on
Sorry this is going to sound like a ridiculous question but can methods (not
I know this should be simple but can't figure it out. Here's the code.
I've tried searching through search engines,MSDN,etc. but can't anything. Sorry if this has been
Sorry if this has already been answered, but I can't find it if so.
Sorry, I know this is programming 101, but I can't find any good documentation...
Sorry for the unhelpful title, but hopefully I can explain this well enough. Lets

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.