INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Jobs

Positioning elements, how do I do it ?!

Positioning elements, how do I do it ?!

(OP)
Hi everyone,
I try to work with css's position but it seems like I cannot handle it.
My code is consisted of a table inside a div.
The div's postion style is "relative" so that its' attributes will refer to the html page.
The table's position attribute is "absolute" so it should relate to its' ancestor: the above described div.
When I run the following code, the table disappears !
Why ?!

CODE

<html !doctype>
<head>
<style>
html, body, div, span, h1, h2, h3, h4, h5, h6, p, blockquote,a, abbr, acronym, address, big, cite, del, 
dfn, em, img, ins, kbd, small, strike, strong, sub, sup, tt, var,b, u, i, center,dl, dt, dd, ol, ul, li,
fieldset, form, label, legend,table, caption, tbody, tfoot, thead, tr, th, td,article, aside, canvas, 
details, embed, figure, figcaption, footer, header, hgroup, menu, nav, output, ruby, section, summary,time, 
mark, audio, video 	{margin: 0;	padding: 0;	border: 0;	font-size: 100%;font: inherit;vertical-align: baseline;}
.wrap {margin-top: 10%; margin-right: auto; margin-bottom: 10% margin-left:auto; position: relative; border-style: dashed; overflow:hidden;}
.myTable {direction:rtl; width:100% ; border-collapse: collapse; border: 1px solid black;position: absolute}
</style>
</head>
<body>
  <div class="wrap">
  <table class = "myTable">
    <tr>
      <th>a</th>
      <th>b</th> 
      <th>c/th>
    </tr>
    <tr>
      <td>1</td> 
      <td>2</td>
      <td>3</td>
    </tr>
    <tr>
      <td>1</td> 
      <td>2</td>
      <td>3</td>
    </tr>
    <tr>
      <td>4</td> 
      <td>5</td>
      <td>6</td>
    </tr>
    </table>
  </div>
</body>
</html> 

RE: Positioning elements, how do I do it ?!

Quote:

The div's postion style is "relative" so that its' attributes will refer to the html page.

Nope. that is the most common misconception about positioning.

position: relative; is 'relative' to where the the element would be when positioned statically (the default)

position: absolute; is 'relative' to the 'page' layout, unless constrained by a 'non-static' parent.

Self promo link drop.
http://webmaster-talk.eu/articles/8-website-develo...

Chris.

Indifference will be the downfall of mankind, but who cares?
Time flies like an arrow, however, fruit flies like a banana.

Never mind these jesus character, stars had to die for me to live.

RE: Positioning elements, how do I do it ?!

Absolutely positioning an element takes it out of the document flow, so it has no bearing on its parent's height.

Your table is being hidden in the non-visible area of the "wrap" div, since your div has an overflow set to hidden.

You also have some errors in your CSS, so some rules aren't being applied. And an error in your HTML.

You have two choices depending on what exactly you want the result to be. Either you increase the "wrap" div's height so the table is visible, or remove the absolute positioning on the table so it affects the div's height.


As a rule of thumb, absolute positioning should be mostly avoided unless you absolutely need to have the element positioned somewhere specifically. Your code does not reflect this, so can't say whether you really need it or not. (Pun was intended)

----------------------------------
Phil AKA Vacunita
----------------------------------
OS-ception: Running Linux on a Virtual Machine in Windows which itself is running in a Virtual Machine on Mac OSx.

Web & Tech

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members!

Resources

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close