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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T08:08:04+00:00 2026-06-10T08:08:04+00:00

You may think it was duplicated, but I don’t thinks so, because I’m talking

  • 0

You may think it was duplicated, but I don’t thinks so, because I’m talking about tables not images!

I tried to set a table in center of div horizontally and vertically with the below codes.
The codes work fine for images but when I put a table instead of image, it seems it can not see the tables and then put the span size to 100% and table display below of div not in center of div.

Codes:

<style>
.wraptocenter {
    display: table-cell;
    text-align: center;
    vertical-align: middle;
    width:155px;
    height: 160px;
    background-color:#999;
    display: block;
}
.wraptocenter * {
    vertical-align: middle;
}

.wraptocenter span {
    display: inline-block;
    height: 100%;
    width: 1px;
}

</style>
<!--[if lt IE 8]><style>
.wraptocenter span {
    display: inline-block;
    height: 100%;
}
</style><![endif]-->
<div class="wraptocenter">
    <span></span>
    <table border="1" width=" 70%">
        <tr height="10px">
            <td width="10px" height="10px"></td>
            <td width="10px" height="10px"></td>
        </tr>
        <tr height="10px">
            <td height="10px"></td>
            <td height="10px"></td>
        </tr>
    </table>
</div>

If you put a images every thing work fine but for tables NOT!

  • 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-10T08:08:05+00:00Added an answer on June 10, 2026 at 8:08 am

    See http://jsfiddle.net/FW2Af/

    Your code only center elements with display:inline-block, such as images. But a table has display:table.

    Then, you can solve it creating a div with display:inline-block which contains your table.

    And if you want table’s width to be 70% of wraptocenter`s width:

    • Set width:100% to the table
    • Set width:70% to the container div.

    Moreover, you have width="10px" on the top cells. If the table has a width of 70%, that’s nonsense.

    Edit:

    I have fixed for IE 7 (and before), because if you set display:inline-block to an element which is a block, it continues being a block, so you have to set diplay:inline in order to make it be display:inline-block:

    <!--[if lt IE 8]><style>
    .wraptocenter>div{
        display:inline;
    }
    </style><![endif]-->
    

    Moreover, the white spaces between the <span> and the <div> are shown on some browsers, so the table isn’t completely centered.

    The solution is:

    .wraptocenter {
        font-size:0;
    }
    .wraptocenter>div{
        font-size:16px; /* Or whatever you want */
    }
    

    (Font: https://stackoverflow.com/a/8902198/1529630, it’s a great idea because in this case using floating would break the centering)

    See it here: http://jsfiddle.net/FW2Af/2/

    Edit 3:

    You say that on IE 8 nothing is shown. For me it works but instead of a black border, it’s white. Fixed here: http://jsfiddle.net/FW2Af/3/

    .wraptocenter td{
        border:1px solid black;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I think my question may be a duplicate, but I do not know what
This probably looks like a duplicate but I don't think so. I have already
First, this may be marked as duplicate question, but the other questions were not
I've found what I think may be a bug with Ivar and Objective-C runtime.
Being new to VS, how may I think of these two concepts, what is
When I send the SMS I am getting NullPointerException . I think may be
I think I may have encountered a bug in mysql, or is it just
I think I may have a misunderstanding of <xsl:variable\> and <xsl:value-of\> so perhaps someone
I think I may have accidently disabled stylecop in my Visual Studio 2008 enviroment.
I think I may be a bit confused on the syntax of the Moq

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.