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

前端 未结 7 1667
忘了有多久
忘了有多久 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 01:11

    You can use margin for .wrap container instead of padding for .wrapper:

    body{ height:20000px }
    #wrapper { padding: 0%; }
    #wrap{ 
        float: left;
        position: relative;
        margin: 10%;
        width: 40%; 
        background:#ccc; 
    }
    #fixed{ 
        position:fixed;
        width:inherit;
        padding:0px; 
        height:10px;
        background-color:#333;    
    }
    

    jsfiddle

提交回复
热议问题