css - Why does fixed positioning alter the width of an element? -


i have <div> has width set 100%. when add position:fixed it, width becomes 16px larger.

i noticed on body, there 8px margins on sides, guessing position:fixed somehow ignoring margins of body tag in contained.

i looked @ mdn reference unable find explains going on.

what has position:fixed changed <div> causes behavior?

example: http://jsfiddle.net/upexv/

the body automatically has margin of 8px. when set width of element 100%, becomes width of body, less 8px on both sides.

but when give element position:fixed, no longer set relative body viewport, doesn't have margins. width width of viewport, 2 * 8px wider - 16px observe.

here's w3 documentation on subject:

whereas position , dimensions of element position:absolute relative containing block, position , dimensions of element position:fixed relative initial containing block. viewport: browser window or paper’s page box.


Comments

Popular posts from this blog

java - Jmockit String final length method mocking Issue -

asp.net - Razor Page Hosted on IIS 6 Fails Every Morning -

c++ - wxwidget compiling on windows command prompt -