绝对定位右下角对齐的核心是同时设置right:0和bottom:0,使元素右、下边界紧贴包含块对应边缘;包含块为最近的定位祖先(relative/absolute/fixed/sticky),无则退化为视口。
用 position: absolute 实现右下角对齐,关键不是“贴右下”,而是**让元素的右边界和下边界分别紧贴其包含块(containing block)的右、下边缘**。这必须同时设置 right: 0 和 bottom: 0,缺一不可。
注意:该包含

position 值为 relative、absolute、fixed 或 sticky 的祖先元素;若没有,则退化为初始包含块(通常是视口)。
right: 0 不够只写 right: 0 会让元素右对齐,但垂直方向仍按正常文档流或默认 top: auto 计算,通常会卡在顶部附近,离“右下角”差很远。
top 和 bottom 是互斥优先级关系:当两者都未显式设置时,top 由文档流决定;一旦设了 bottom,浏览器就放弃自动计算 top,转而根据 bottom + 高度反推位置bottom: 0 就能确保底边锚定,无需知道具体高left 或 top 是安全的——它们会自然变为 auto,不影响 right/bottom 生效实际写的时候容易掉进这几个坑:
position: relative,导致元素相对整个页面定位(尤其在滚动页中“漂”到视口右下,而非预期容器右下)padding 或 border,但忘记用 box-sizing: border-box,导致 right: 0; bottom: 0 后元素被遮挡或溢出align-self: flex-end 和 absolute 混用能简化逻辑right/bottom,但 IE7 及更早需 hack;现代项目基本不用考虑下面这段 HTML/CSS 能稳定把按钮钉在容器右下角:
.container {
position: relative;
width: 300px;
height: 200px;
border: 1px solid #ccc;
}
.button {
position: absolute;
right: 12px;
bottom: 12px;
}
其中 right: 12px 和 bottom: 12px 是常用内边距值;如果要贴死边缘,就写 0。真正要注意的,永远是那个 position: relative 的父容器——它看不见,但缺它就全乱。