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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T13:19:26+00:00 2026-05-20T13:19:26+00:00

As an experiment, I’ve been trying to center a DIV in a BODY tag

  • 0

As an experiment, I’ve been trying to center a DIV in a BODY tag using percentages in CSS. I think I had it figured out at one point, but thanks to the magic of TopStyle not having a history once you save, I lost it.

So, here is my HTML:

<html>
    <head>
        <link href="shadow.css" rel="stylesheet" type="text/css" />
    </head>
    <body>
        <div id="box"></div>
    </body>
</html>

And, here is my CSS:

*
{
    margin: 0;
    padding: 0;
}

body
{
    background-color: #EEEEEE;
    margin: 10%;
}

div#box
{
    position: absolute;
    background-color: #FFFFFF;
    width: 740px;
    min-width: 80%;
    min-height: 80%;
    border: #CCCCCC thin solid;
}

To answer your immediate questions:

Why am I using absolute positioning on the box?
So that the box will accept 80% as it’s height even without content to stretch it.

Why am I width, min-width and min-height like this?
Since I want the box DIV to take up 80% of the available space, it made sense to use minimums. I’m using a pixel width to make sure that no matter how small the area gets, it won’t go any thinner than 740px, causing the browser to activate the horizontal scroll bar. In theory, they content height should activate the vertical scroll bar if the content pushes passed 80% of the available area.

Now the trick is to get it dead centered and maintain a 10% space around the box. I’ve tried applying “margin: 10%;” to BODY, then “padding: 10%;” to BODY, and finally “margin: 10%” to the box DIV. All of those choices gives me the same result: it’s centered horizontally but is acting strange vertically. I’m not getting even space on all sides. The only thing that is behaving as wanted is that the box DIV does appear to be using 80% of the available space.

It seems like this should be right. The box DIV is taking up 80%, the margins are taking up 10% on each side (20% vertically and 20% horizontally), making 100%. Not sure why it’s not working.

I swear I had this working in a similar manner, and now I’ve lost it.

Does anyone have an explanation as to why the percentages don’t seem to be displaying correctly and what solution I would need?

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-20T13:19:26+00:00Added an answer on May 20, 2026 at 1:19 pm

    Try it like this:

    *
    {
        margin: 0;
        padding: 0;
    }
    
    body { background-color: #EEEEEE; }
    
    div#box
    {
        position: absolute;
        border: #CCCCCC thin solid;
    
        top: 10%;
        left: 10%;
    
        width: 80%;
        height: 80%;
    
        min-width: 740px;
        min-height: 500px;    
    }
    

    IE will allow for the DIV to shrink below your limits since min-width and min-height do not work.

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

Sidebar

Related Questions

I'm trying to experiment with Microsoft.Web.Administration on my Windows 7 x64 box, using Visual
I am beginning to experiment with Cassandra. I am trying out the sstable2json backup
I am trying to experiment using basic shaders in my program, I came across
I'm trying to experiment with SVG on Firefox. Since I'm using jQuery, I'd like
I am trying to experiment this parameter in MapReduce and I have some question.
As an experiment we want to build our products using the Eclipse java compiler
As an experiment I'm trying to write a generic MVP framework. I started with:
I experiment with my applet using Eclipse and its Applet Viewer. The Applet Viewer
As an experiment, I am trying to build the following hierarchy of methods around
As an experiment, I am trying to make a void member function with no

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.