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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T00:47:10+00:00 2026-06-08T00:47:10+00:00

I know that it’s a newbie question, but if you could give me a

  • 0

I know that it’s a newbie question, but if you could give me a hand and tell me what I’m doing wrong I’d really appreciate that:

While I was experimenting with HTML and CSS I decided to create a page with a fixed size that should be centered on the screen. To do so I decided to place the [body] tag by making its position relative and move it by writing:

position: absolute;
padding: 1em;
width: 960px;
height: 600px;
left: 50%;
top: 50%;
margin-left: -480px;
margin-top: -300px;

Hovever it didn’t worked quite as expected, and this is the result I’m getting:

Screenshot taken from the page

I was expecting to see the yellow box perfectly centered both horizontally and vertically, but instead I see that it’s slightly off-center.
I tried to load the page on Safari, Firefox and Chrome and I’m getting the same results so as I already suspected I know that it’s my fault 🙂

Could you help me by explaining what I did wrong ?
Thank you very much

This is the complete HTML+CSS code of the page I have written:

<!DOCTYPE html>
<html>
<head>
    <title>Test 1</title>
    <meta charset="utf-8">
    <style>
        html, body {
            padding: 0;
            margin: 0;
        }
        html {
            background-color: red;
            width: 100%;
            min-height: 100%;
            font-family: Helvetica, Arial, sans-serif;
            font-size: 16px;
        }
        body {
            padding: 1em;
            background-color: yellow;
            width: 960px;
            height: 600px;
            position: absolute;
            left: 50%;
            top: 50%;
            margin-left: -480px;
            margin-top: -300px;
        }
    </style>
</head>
<body>
    This is my website
</body>
</html>
  • 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-08T00:47:12+00:00Added an answer on June 8, 2026 at 12:47 am

    That’s because of the padding.

    If you set the padding of the body to 0, it works (tested).

    If you need a padding, add an internal 100% width div inside your body and give this internal div a padding.

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

Sidebar

Related Questions

I know that this is really not a smart question, but I have some
I know that this sort of question has been asked here before, but still
I know that this question has been asked quite a few times, but I
I know that question has been repeatedly asked in different ways, but I tried
I know that this question has been asked in various forms but my requirement
I know that there has been one question about this but it is not
I know that question was discussed plenty of times, but i tried all suggestions
I know that this is not really clean but it is possible as I
I know that they are already a lot of question about the subject but
I know that Phonegap has an event for back button, but it's only available

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.