Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Position overlay div

Tags:

css

I have a link in a table cell and when the link is clicked I show a hidden div.

Currently I use position: absolute and z-index:10. It works fine, but I would like to move it a bit to the top and left. When I add top: -10px and left: -10px, the div moves to the position of the window.

How do I make it 10px off the table cell?

like image 519
santa Avatar asked Dec 22 '22 13:12

santa


1 Answers

You need to set the parent element using position relative then use position absolute on the element you want to position. So if you want it to be positioned based on the table you need to add position: relative to the table (which won't do anything because it is already positioned relative) and position: absolute to the overlay. Absolute positioning takes the element out of the document flow and relative positioning leaves it in the document flow which is why stuff is being moved around. The reason for this is based off how CSS works: http://www.w3schools.com/css/pr_class_position.asp

relative The element is positioned relative to its normal position, so "left:20" adds 20 pixels to the element's LEFT position

absolute The element is positioned relative to its first positioned (not static) ancestor element

You might also be interested in fixed.

fixed The element is positioned relative to the browser window

Here is an Example: http://pastehtml.com/view/av391nzsv.html

like image 138
m4tt1mus Avatar answered Jan 12 '23 00:01

m4tt1mus