css - Can I position an element fixed relative to parent? -


i find when position element fixed, doesn't matter if parent positioned relative or not, position fixed, relative window?

css

#wrapper { width: 300px; background: orange; margin: 0 auto; position: relative; } #feedback { position: fixed; right: 0; top: 120px; } 

html

<div id="wrapper">     ...     <a id="feedback" href="#">feedback</a> </div> 

http://jsbin.com/ibesa3

let me provide answers both possible questions. note existing title (and original post) ask question different seek in edit , subsequent comment.


to position element "fixed" relative parent element, want position:absolute on child element, , position mode other default or static on parent element.

for example:

#parentdiv { position:relative; } #childdiv { position:absolute; left:50px; top:20px; } 

this position childdiv element 50 pixels left , 20 pixels down relative parentdiv's position.


to position element "fixed" relative window, want position:fixed, , can use top:, left:, right:, , bottom: position see fit.

for example:

#yourdiv { position:fixed; bottom:40px; right:40px; } 

this position yourdiv fixed relative web browser window, 40 pixels bottom edge , 40 pixels right edge.


Comments

Popular posts from this blog

c# - How to set Z index when using WPF DrawingContext? -

razor - Is this a bug in WebMatrix PageData? -

visual c++ - Using relative values in array sorting ( asm ) -