How can I have a fixed div next to a parent div?

前端 未结 3 1321
旧时难觅i
旧时难觅i 2020-12-22 05:05

I\'m trying to get a div with a button next to a parent div. Like this:

____________
|relative  |
|          |
|          |
|          |_______
|          |          


        
3条回答
  •  误落风尘
    2020-12-22 05:58

    Use position:fixed for the second div

    HTML

    zx

    CSS

    html, body{
        height:100%;
        margin:0
    }
    .main{
        height:100%;
        width:50%;
        background:grey;
    }
    .fix{
         position:fixed;
         top:50%;
         border:red solid 2px;
         background:yellow;
         left:50%
    }
    

    DEMO

提交回复
热议问题