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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T20:30:09+00:00 2026-05-28T20:30:09+00:00

I am trying to vertically and horizontally center a container, and the content inside

  • 0

I am trying to vertically and horizontally center a container, and the content inside using CSS.

The markup looks like this:

<div id="container">
  <img src="..someimage.jpg">
  <img src="..someverticaldivider">
  <form action="action.php">
    <input type="text">
    .... (other inputs)
  </form>
</div>

I need the end result to look like this:
result

So far, my css looks like this:

#content{
     position:absolute;
     width: 900px; 
     left:50%;
     top:50%;
     height:300px;
     margin-top:-150px;
     margin-left: -450px; 

}

That works fine and if I add a border to #content, I can easily see that it is indeed centered horizontally and vertically.

The problem I am facing is that I do not know the size of the content inside #content. I need to be able to align those elements 2 images and 1 form horizontally and vertically. I have checked out this site for vertically centering, but the problem is that I do not know the size of my content, and the content is not only text.

What is the best way to do this with support for older browsers (IE7 and up)?

  • 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-28T20:30:10+00:00Added an answer on May 28, 2026 at 8:30 pm

    edit 1
    And here is the the final result of the jury
    This centers also the content inside the box vertically (image, vertical ruler, form)
    http://jsfiddle.net/HerrSerker/TuPvF/13/


    I’m trying to give an authoritative answer to this.
    Maybe this won’t work in mobile browsing (smart phones, iPad etc.). Could anyone check?

    Use display: table and display: table-cell in modern browsers which support them to make use of the vertical-align which works with them.

    Use positioning with relative measures in some old IE browsers

    http://jsfiddle.net/HerrSerker/TuPvF/


    <!-- HTML -->
    <div class="table">
        <div class="cell">
            <div class="inner">
                <div class="align">
                    <img src="//lorempixel.com/200/300">
                </div>
                <div class="align">
                    <img src="//lorempixel.com/200/200">
                </div>
            </div>
        </div>
    </div>
    

    /* all css rules prepended by a hash sign (#) are specifically for IE 7 and below */
    
    html, body {
         /* w3c dropped height percentage in some css2 or so version 
          * if you don't know the heights of ALL the parent element up to the root.
          * So give ALL parents a known height
          * CAVE: If mobile browsing is important check, if this does not affect scrolling and zooming
          */
        height: 100%; 
    }
    .table{
        /* modern browsers support display: table
         * use this for an easy vertical alignment
         */
        height: 100%;
        width: 100%;
        display: table;
        /* check if you want absolute positioning */
        position: absolute;
        /* if you don't want absolute positioning, uncomment the next line and comment the previous line out */
        /* #position: relative */ 
    }
    .table > .cell {
         /* modern browsers support display: table-cell
         * use this for an easy vertical alignment
         * You don't need table-row
         */     
        display: table-cell;
        vertical-align: middle;
        text-align: center;
        /* this is again for lte IE7 */
        #position: absolute;
        /* 50% is half of the containing element (.table here) */
        #top: 50%;
        #width: 100%;
    }
    .cell > .inner {
        text-align: left;
        display: inline-block;
        /* triggers hasLayout in IE 6+7 */    
        #zoom: 1;
        /* if IE 6+7 element have hasLayout, display: inline behaves as display: inline-block. Strange, huh?  */
        #display: inline;
        #position: relative;
        /* here the 50% are the half of the .cell element */
        #top: -50%;
    }
    .cell > .inner > .align {
        vertical-align: middle;
        display: inline-block;
        #zoom: 1;
        #display: inline;
    }
    
    
    .inner {
        border: 1px solid gold;
        padding: 10px;
        white-space: nowrap;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to horizontally and vertically center a modal window inside a div. I
I'm trying to center both horizontally and vertically a div inside an outer div.
I have a navigation menu with css. I'm trying to vertically and horizontally center
I gave up on trying to center an image vertically and horizontally. I seen
I'm trying to center an edittext vertically and horizontally in a linear layout, but
I'm trying to center 1 #div box with two small #divs inside of it,
I'm trying to make an horizontal menu, vertically and horizontally aligned. I'm actually using
Ok, so I am trying to center a div with dynamic content ( both
I am trying to determine how to center (vertically and horizontally) buttons in a
I'm trying to center a View vertically on screen with the following layout: <?xml

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.