button position absolute not working as expected

后端 未结 7 1339
礼貌的吻别
礼貌的吻别 2021-02-20 05:49

Can anyone explain why this button is not absolute-positioned to the right? I would expect it to be 3px from every edge.

7条回答
  •  有刺的猬
    2021-02-20 06:16

    You might want to use inherit/100% value for width and height css properties.

    .wrapper {
        height: 300px;
        width: 300px;
        background-color: #f33;
        padding: 3px;
    }
    .wrapper button {
        width: inherit;
        height: inherit;
    }
    

    Fiddle

    NOTE: If you want to have the dimensions exactly 300 then subtract padding. (which will be 294px)

提交回复
热议问题