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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T10:02:53+00:00 2026-06-12T10:02:53+00:00

There are two questions. Firstly, if there is no height set on divs, and

  • 0

There are two questions.

  1. Firstly, if there is no height set on divs, and there is no element
    contained inside them, won’t they display at all?

  2. Secondly, depending on the first question, if I want to display a
    div to be 90% of the body height and centered both horizontally and
    vertically, even if there is no content inside of it, what is the
    css required?

  • 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-12T10:02:53+00:00Added an answer on June 12, 2026 at 10:02 am

    To completely centre a div (or any block element) you should use absolute positioning in combination with negative margins. Take a look here: enter link description here. Try resizing the window: it’s positioning happens automatically.

    div {
        width: 90%;  /* Can be a non-percentual number */
        margin-left: -45%; /* negative value of element's width/2 | Can be a non-percentual number */
        margin-top: -45%; /* negative value of element's height/2 | Can be a non-percentual number */
        height: 90%;  /* Can be a non-percentual number */
        position: absolute;
        top: 50%; /* must always be 50% */
        left: 50%; /* must always be 50% */
        border: 1px solid;
    }​
    

    Of course, when you are only using percentual values, it is easier to just do the math: 50% – 45% = 5% (as Zeta’s post suggest) but I used this method to show that this works with non-percentual values as well. Example.

    div {
        width: 320px;
        margin-left: -160px; /* negative value of element's width/2 */
        margin-top: -120px; /* negative value of element's height/2 */
        height: 240px;
        position: absolute;
        top: 50%; /* must always be 50% */
        left: 50%; /* must always be 50% */
        border: 1px solid;
    }​
    

    When an element does not have a specific height and it doesn’t have content, you will not see it, no. It will have an automatic width (normally 100%) but no height. You can make it visible though, by adding a border: http://jsfiddle.net/TALAA/2/

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

Sidebar

Related Questions

There are two questions to this: How can I best spread the word about
There are two similar questions asked here and here but no adequate answers are
Two questions, really: Is there a standard/convention regarding the placement on configuration files? For
Actually I have two questions. (1) Is there any reduction in processing power or
I have read a document that they say: In java there two types of
This is a two part question; firstly, does anyone out there have some insight
This is probably two questions in one.... Firstly i wonder how does android run
There are two parts to my question - Firstly we can attach event handlers
I have two questions about Compound-Statement and Transactions in MySQL. FIRST: There are two
I have two questions. Question #1: What is the difference between HttpWebResponse.Cookies and WebResponse.Headers[Set-Cookie]?

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.