button position absolute not working as expected

后端 未结 7 1324
礼貌的吻别
礼貌的吻别 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:37

    You need to set the width of the button, to make it fill the space.

    The easiest way to do this is to set it to the correct size.

    .wrapper {
        height: 300px;
        width: 300px;
        background-color: #f33;
        position: relative;
    }
    
    .wrapper button {
        position: absolute;
        top: 3px;
        bottom: 3px;
        left: 3px;
        right: 3px;
        height: 294px;
        width: 294px;
    }
    

提交回复
热议问题