The effect of 'position:relative' on table-row-group, table-header-group, table-footer-group, table-row, table-column-group, table-column, table-cell, and table-caption elements is undefined.
Source: http://www.w3.org/TR/CSS21/visuren.html#propdef-position
Is there any idea to position relative to which I have set display property to table-cell using :before or :after selector?
.someclass{display: table-cell; position: relative; z-index: auto;}
/*this won't work*/
There is a kinda hacky way without additional elements using negative margin:
http://jsfiddle.net/CvyxM/1/
You simply position the element relative to the cell, while eliminating its dimensional impact on other elements by adding negative margins on all sides in correlation to the elements own dimensions.
Problem here is that the positioned element must have fixed dimensions (can't work with percentage negative margin because that depends on the outer element).
The other, probably more common solution is to add an additional wrapper element inside the cell width position relative and position other child elements absolute to this wrapper.
IMHO: In browsers which support CSS3
position:relative
on table elements should work. It now works only in Firefox.Sources:
https://www.w3.org/TR/css-position-3/#valdef-position-relative
https://www.w3.org/TR/css-position-3/#property-index
https://developer.mozilla.org/en-US/docs/Web/CSS/position#relative About 'stacking context' but that is not the subject of this question
Related questions: