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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T14:13:58+00:00 2026-05-13T14:13:58+00:00

First, here’s is my rough example: http://demindu.com/sandbox/simple.html What I’m trying to do: Create a

  • 0

First, here’s is my rough example: http://demindu.com/sandbox/simple.html

What I’m trying to do:

Create a content div: let’s say 400px tall and 700px wide, like the example. The content box has a margin of 50px in each direction. The content div should always be centered both vertically and horizontally, regardless of screen resolution. The black background should extend from the centered content area all the way to the right side of the screen, but not to the left.

The only way I can think of possibly doing this is something using window.innerWidth & window.innerHeight in JavaScript, but I don’t know enough to know if this is even possible.

The amount of blank space above and below the middle section would need to be:
window.innerHeight – height of the div (in this example: 500px [400px box with two 50px margins]) / 2

The blank space to the left of the black bar would need to be:
window.innerWidth – width of the div (in this example: 800px [700px box with two 50px margins]) / 2

My question to you is: Is this possible in JavaScript? Is this possible somehow with pure CSS?

  • 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-13T14:13:59+00:00Added an answer on May 13, 2026 at 2:13 pm

    You can do this entirely in CSS with 4-point absolute positioning. You will need two elements:

    1. The first item spans from the right of the screen to the center where the content is positioned. This element uses absolute positioning for the top, left, and right coordinates of the element (we can leave bottom unspecified as it’s taken care of by the height.)

    2. The second item is nested in the former. This item has a fixed width to ensure the content itself remains in the specified width you’ve chosen. We can also set the height and padding on this object and the parent will inherit it’s height. Don’t use margins to simulate padding – it can cause cross browser issues when you’re just trying to do some positioning tricks as we are here.

    So your HTML code would look something like this:

        <div id="my_centered_design">
            <div id="my_centered_design_content">
                <p>This is just some example text.</p>
            </div>
        </div>
    

    And you’re CSS would look like this:

        div#my_centered_design {
          background: #000;
          margin-left: -400px;
          margin-top: -250px;
          left: 50%;
          position: absolute;
          right: 0;
          top: 50%;
       }
    
       div#my_centered_design_content {
          background: #333;
          height: 400px;
          /* I think you actually want padding for 
             the effect you're trying to accomplish */
          padding: 50px;
          width: 700px;
       }
    

    Essentially this is the same trick as the Joe2Tutorial except we are applying additional positioning rules to adhere the centered element to the right side of the screen.

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

Sidebar

Related Questions

First off here is the code! <!DOCTYPE html PUBLIC -//W3C//DTD XHTML 1.0 Strict//EN http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd>
first here is my html demo code <div class=wrapper> <div class=item></div> <div class=item></div> <div
first here is my html code: <div class=outter> <div class=item></div> <div class=item></div> <div class=item></div>
First here's what I'm using and trying to do: the minimal setup for this
first question here, be nice :P I am trying to make an infinite UIScrollView
first poster here. Trying to use sed to find and replace a word. Code
first off here's my current code. <div id=background> <img src=src/1080pTux.png height=100%> </div> #background{ position:fixed;
Helly guys, first here the jsfiddle example and here my problem. I have 3
First off here is my code: CREATE FUNCTION unknown_Model () RETURNS TRIGGER LANGUAGE plpgsql
I got some simple CSS from http://www.cssstickyfooter.com/ to get a footer that always sticks

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.