如何在 CSS 中使用绝对定位使按钮不受 padding 影响
.container {
position: relative;
padding: 20px;
background-color: #f2f2f2;
}
button {
position: absolute;
top: 0;
left: 0;
}
在上述示例中,我们将 '.container' 容器设置为相对定位,并给它添加了 20px 的 padding。然后,将按钮设置为绝对定位,并将其放置在容器的左上角。这样,按钮就不会受到 padding 的影响了。
原文地址: https://www.cveoy.top/t/topic/mV9n 著作权归作者所有。请勿转载和采集!