Can anyone tell me why position:fixed cause the element to be wider than the browser or other content on the page and causing horizontal scrolling?
Here is the code HTML
As Salaw mentioned, using body { margin: 0; }
will solve the issue, since has default margin/padding (depending on the browser).
position: fixed;
removes an element completely from the flow of the document and makes it relative only to the viewport, while position: relative;
does not.
Given this fact, and given that width: 90%
means "make this element take up 90% of parent element's available space", and given that the parent of a fixed
element is the viewport while the parent of this relative
element is the body with its margin, you have the discrepancy in sizes.
See http://codepen.io/anon/pen/exzpC