Fixed position but relative to container

后端 未结 25 2211
独厮守ぢ
独厮守ぢ 2020-11-21 23:52

I am trying to fix a div so it always sticks to the top of the screen, using:

position: fixed;
top: 0px;
right: 0px;

However,

25条回答
  •  孤街浪徒
    2020-11-22 00:45

    /* html */
    
    /* this div exists purely for the purpose of positioning the fixed div it contains */
    
    my fixed content
    /* css */ /* wraps fixed div to get desired fixed outcome */ .fix-my-fixed-div-to-its-parent-not-the-body { float: right; } .im-fixed-within-my-container-div-zone { position: fixed; transform: translate(-100%); }

提交回复
热议问题