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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T15:55:48+00:00 2026-06-05T15:55:48+00:00

I did some research and found that the only way to vertically center a

  • 0

I did some research and found that the only way to vertically center a table inside a div(where the table does not span the full height, the height varies with varying content) is with javascript/jquery:

<script>
   var tableMarginTop = Math.round( (testHeight - tableHeight) / 2 );
   $('table').css('margin-top', tableMarginTop)
</script>

Now my code looks like this:
CSS:

.rightDiv{
    width: 300px
    height: 380px;
    background: url(http://myimage.com) no-repeat;
}

.rightDiv table{
    margin: auto; /*For centering horizontally*/
}

HTML:

<div class="rightDiv">
  <table width="80%">
    <tr><td></td></tr>
  </table>
</div>

My question: How to I implement that code for this situation? Not sure how to call the specific div class and table class in the JS function for the relevant div and table?

Thank You

  • 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-05T15:55:51+00:00Added an answer on June 5, 2026 at 3:55 pm

    This answer is for the question:

    My question: How to I implement that code for this situation? Not sure how to call the specific div class and table class in the JS function for the relevant div and table?

    “.rightDiv” and “.rightDiv table” at your sample offers nothing! Make it simpler.

    CSS

    #rightDiv{
        width: 300px
        height: 380px;
        background: url(http://myimage.com) no-repeat;
    }
    
    #rightDivTable{
        margin: auto; /*For centering horizontally*/
    }
    

    HTML

    <div id="rightDiv">
      <table id="rightDivTable" width="80%">
        <tr><td></td></tr>
      </table>
    </div>
    

    UPDATE: added missing quotes and requested code

    This way you will use $(‘#rightDiv’) and $(‘#rightDivTable’) in jquery for your elements.

    JS

    var 
        testHeight = $('#rightDiv').innerHeight(),
        tableHeight = $('#rightDivTable').outerHeight(),    
        tableMarginTop = Math.round( (testHeight - tableHeight) / 2 );
        $('#rightDivTable').css('margin-top', tableMarginTop);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

after I did some research on the subject, I found that Windows Live stopped
After did some research, I found that there are some websites( e.g. http://www.topappcharts.com )
I did some research into the easiest/best way to generate a pdf in my
I did some research but all I could find was syncing data core with
I did some research but couldn't find the answer I was looking for so
I did some research but cannot find a definite approval or disapproval. What I
Did some searches here & on the 'net and haven't found a good answer
I did some changes and then did a commit. Then I realized that I
Been getting a lot of errors like this lately. I did some research and
I have a stored procedure that does some parameter validation and should fail and

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.