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

  • Home
  • SEARCH
  • 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 6161569
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T21:30:10+00:00 2026-05-23T21:30:10+00:00

I need to position something with absolute positioning inside a td. To get around

  • 0

I need to position something with absolute positioning inside a td. To get around the fact that a td is undefined when setting it to relative, I use a div set to relative inside my td then inside that div I have an inner div set to absolute. This all works great when I have content filling up the td. When I set the content of the td to display none then the absolute positioning gets all screwed up.

Does anyone know why this would be.

HTML:

<table>
    <tr>
        <td>
            <div class="relative">
                <div class='absolute'>
                    <p>A</p>
                </div>
            </div>
            <div class="slot"></div>
            <div class="slot"></div>
        </td>
        <td>
          <div class="relative">
             <div class='absolute'>
               <p>B</p>
           </div>
           </div>
           <div class="slot hidden"></div>
           <div class="slot"></div>
        </td>
    </tr>
</table>

And CSS:

td{
    border:1px solid red;
    width:100px;
    height:60px;
    vertical-align:bottom;
}

.slot{
  width:100px;
  height:29px;
  background-color:#999;
  border:1px dashed blue;
}

.relative{
    position:relative;
}

.absolute{
    position:absolute;
    top:5px;
    left:5px;
}
.hidden{
    display:none;
}

And a live version: http://jsfiddle.net/HgEtQ/

In the fiddle above you can see the first table cell works correctly. The absolutely positioned div is in the correct space. The second one has hidden the top slot and now the absolute positioning is not in the top left corner anymore. If you take out both slots then it really screws up the absolute positioning. I need to positioning it absolute because some of the elements will be shifted depending on the element.

  • 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-23T21:30:11+00:00Added an answer on May 23, 2026 at 9:30 pm

    There are a couple things going on here.

    You have this:

    td {
        /*...*/
        vertical-align:bottom;
    }
    

    That will push the content of the cells to the bottom.

    Also, an absolutely positioned element is removed from the normal flow so it won’t contribute to its parent’s height:

    It is removed from the normal flow entirely (it has no impact on later siblings). An absolutely positioned box establishes a new containing block for normal flow children and absolutely (but not fixed) positioned descendants.

    In particular, this means that your div.relative elements have a height of zero but they will still have an upper left corner so your absolute positioning offsets are anchored somewhere.

    Then you have <div class="slot hidden"> and the hidden removes the <div> from the layout so you effectively have just this:

    <div class="relative"></div> <!-- Height zero -->
    <div class="slot"></div>     <!-- Height 29px -->
    

    That combined with the vertical-align: bottom means that your second div.absolute will be positioned 5px from the top of the div.slot and that is 25px from the bottom of the table cell.

    The first cell works fine because the two visible div.slot elements push the div.relative right to the top of the cell, then the div.absolute is positioned 5px from the top of the div.relative and that is 5px from the top of the table cell.

    Unfortunately, adding position: relative to a <td> is a bit dodgy as far as browsers go so you’ll need some hackery to get your positioning right while keeping vertical-align: bottom. You could re-structure the <td>s like this:

    <td>
        <div class="relative">
            <div class='absolute'>
                <p>A</p>
            </div>
        </div>
        <div class="nonsense">
            <div class="slot"></div>
            <div class="slot"></div>
        </div>
    </td>
    

    And the CSS like this:

    td{
        border:1px solid red;
        width:100px;
        height:60px;
        vertical-align: top;
    }
    
    .slot{
        width:100px;
        height:29px;
        background-color:#999;
        border:1px dashed blue;
    }
    
    .relative {
        position:relative;
    }
    .nonsense {
        height: 62px; /* td[height] + 2 for the borders */
        display: table-cell;
        vertical-align: bottom;
    }
    
    .absolute{
        position:absolute;
        top:5px;
        left:5px;
    }
    .hidden{
        display:none;
    }
    

    Live example: http://jsfiddle.net/ambiguous/aV4nT/

    Or you could use visibility: hidden:

    hidden
    The generated box is invisible (fully transparent, nothing is drawn), but still affects layout. Furthermore, descendants of the element will be visible if they have ‘visibility: visible’.

    instead of display: none for your .hidden class:

    .hidden {
        visibility: hidden;
    }
    

    This will leave both div.slot elements taking up space and affecting the layout but only the second one will be seen.

    Live example: http://jsfiddle.net/ambiguous/RcdNh/

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

Sidebar

Related Questions

I need something to get the position of a sub-sub element relative to the
This is a form validation for jquery: http://www.position-absolute.com/articles/jquery-form-validator-because-form-validation-is-a-mess/ I need something like that but
I need to position a div over an image with jQuery. I can create
I have an Panel control that I need to maintain position across postbacks. I
I'd like to position a div on top of another div, but absolutely, something
I have some anchor elements, but they are in absolute position div and the
I have an array of objects that I need to sort by a position
It's my understanding that position: absolute is absolute to the first parent who has
im trying to get some background images around a content div. Thing is, the
I'm working on a website that has a rotation of testimonials. I need something

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.