css - Can I position an element fixed relative to parent? -
this question has answer here:
- fixed position relative container 19 answers
- css position element “fixed” inside scrolling container 3 answers
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>
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
Post a Comment