Layout of Absolutely Positioned Elements
In the following sections, these terms are used:
- Shrink-to-fit
Similar to calculating the width of a table cell using the automatic table layout algorithm. In general, the user agent attempts to find the minimum element width that will contain the content and wrap to multiple lines only if wrapping cannot be avoided.
- Static position
The place where an element’s edge would have been placed if its
position
werestatic
.
Horizontal layout of nonreplaced absolutely positioned elements
The equation that governs the layout of these elements is:
left + margin-left + border-left-width + padding-left + width + padding-right + border-right-width + margin-right + right = width of containing block
The steps used to determine layout are:
If all of
left
,width
, andright
areauto
, first reset anyauto
values formargin-left
andmargin-right
to0
. Then, ifdirection
isltr
, setleft
to the static position and apply the rule given in step 3c. Otherwise, setright
to the static position and apply the rule given in step 3a.If none of
left
,width
, andright
isauto
, pick the rule that applies from the following list:If both
margin-left
andmargin-right
are set toauto
, solve the equation under the additional constraint that the two margins get equal values.If only one of
margin-left
ormargin-right
is set toauto
, solve the equation for that value.If the values are overconstrained (none is set to
auto
), ignore the value forleft
ifdirection
isrtl
(ignoreright ...
Get CSS Pocket Reference, 3rd Edition now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.