How to right align fixed position div inside a div

后端 未结 7 2101
庸人自扰
庸人自扰 2021-02-19 19:03

My code is like this.

some text here

CSS:



        
7条回答
  •  小鲜肉
    小鲜肉 (楼主)
    2021-02-19 19:27

    Why don't you use position:absolute

    position:fixed always relative to the browser

    .outer {
        width:200px;
        height:600px;
        background-color:red;
        margin:0 auto;
        position:relative
    }
    .inner {
        width:50px;
        border:1px solid white;
        position:absolute; right:0
    }
    

    DEMO


    If it is compulsory to use position:fixed then you can assign the margin-left value, since you are using fixed with for both the divs.

    .inner {
        width:50px;
        border:1px solid white;
        position:fixed; margin-left:150px
    }
    

    DEMO 2

提交回复
热议问题