Positioning Relative To Table-cell
Solution 1:
IMHO: In browsers which support CSS3position: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
Property name:
position
Applies to: all elements excepttable-column-group
andtable-column
https://developer.mozilla.org/en-US/docs/Web/CSS/position#relative About 'stacking context' but that is not the subject of this question
This value (
position: relative
) creates a new stacking context when the value of z-index is not auto. Its effect ontable-*-group
,table-row
,table-column
,table-cell
, andtable-caption
elements is undefined.
Related questions:
Solution 2:
There is a kinda hacky way without additional elements using negative margin:
tdspan {
display: block;
width: 10px;
height: 10px;
margin: -5px;
background: red;
position: relative;
top: -5px;
left: -5px;
}
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.
Post a Comment for "Positioning Relative To Table-cell"