position: fixed
is always relative to the window/browser, thus it cannot be used to solve your problem. Fixed positioning removes the element from the natural order of the DOM, and thus does not remain within your outer div anymore, hence why it takes the full width of the browser and not of your container. What you need to use is position: absolute
to place .inner
relative to .outer
. You'll be able to position your element as well as have its width be contained by the .outer
div.