css - What are the default top, left, botton or right values when position:absolute is used? -


in big project, few buttons misalligned in ie. found fix coincidence, setting position: absolute without parameters. made me wonder, default values of such position? understand how absolute positioning works , containing element means. don't know default values come from. not top:0; left:0 expected.

<!doctype html> <html> <head> <style> h1 { position:absolute; } </style> </head>  <body> <h1>absoulute pos</h1> <p>paragraph</p> </body>  </html> 

here simple page, , how final positioning of h1 element looks like:

enter image description here

as suspect, initial values these properties not 0; auto. can find property definitions in section 9.3.2 of spec.

when absolutely positioned box keeps offsets auto (i.e. don't modify them), doesn't go anywhere. remains in static position, means usual spot in layout had not been positioned @ all. section 10 has all details (it has entire paragraphs explaining "static position" means), you'll want focus on 10.3.7:

the constraint determines used values these elements is:

'left' + 'margin-left' + 'border-left-width' + 'padding-left' + 'width' + 'padding-right' + 'border-right-width' + 'margin-right' + 'right' = width of containing block

if 3 of 'left', 'width', , 'right' 'auto': first set 'auto' values 'margin-left' , 'margin-right' 0. then, if 'direction' property of element establishing static-position containing block 'ltr' set 'left' static position , apply rule number 3 below; otherwise, set 'right' static position , apply rule number 1 below.

[...]

1. 'left' , 'width' 'auto' , 'right' not 'auto', width shrink-to-fit. solve 'left'

and 10.6.4:

for absolutely positioned elements, used values of vertical dimensions must satisfy constraint:

'top' + 'margin-top' + 'border-top-width' + 'padding-top' + 'height' + 'padding-bottom' + 'border-bottom-width' + 'margin-bottom' + 'bottom' = height of containing block

if 3 of 'top', 'height', , 'bottom' auto, set 'top' static position , apply rule number 3 below.

[...]

3. 'height' , 'bottom' 'auto' , 'top' not 'auto', height based on content per 10.6.7, set 'auto' values 'margin-top' , 'margin-bottom' 0, , solve 'bottom'


Comments

Popular posts from this blog

sql - VB.NET Operand type clash: date is incompatible with int error -

SVG stroke-linecap doesn't work for circles in Firefox? -

python - TypeError: Scalar value for argument 'color' is not numeric in openCV -