Set a Fixed div to 100% width of the parent container

前端 未结 7 1656
忘了有多久
忘了有多久 2020-12-09 00:52

I have a wrapper with some padding, I then have a floating relative div with a percentage width (40%).

Inside the floating relative div I have a fixed div which I w

7条回答
  •  失恋的感觉
    2020-12-09 00:57

    Try adding a transform to the parent (doesn't have to do anything, could be a zero translation) and set the fixed child's width to 100%

    body{ height:20000px }
    #wrapper {padding:10%;}
    #wrap{ 
        float: left;
        position: relative;
        width: 40%; 
        background:#ccc; 
        transform: translate(0, 0);
    }
    #fixed{ 
        position:fixed;
        width:100%;
        padding:0px;
        height:10px;
        background-color:#333;
    }
    Some relative item placed item

提交回复
热议问题