【问题标题】:Aligning position sticky at the bottom right is not working右下角的对齐位置粘性不起作用
【发布时间】:2022-12-16 20:25:24
【问题描述】:
我需要将此按钮固定在屏幕的右下角,但如您所见,我的代码有问题。我错过了什么?
你能帮我吗?
谢谢。
html {
background: #ccc;
}
.chat {
width: 55px;
height: 55px;
position: sticky;
bottom: 20px;
right: 20px;
background: red;
border: 0;
}
<button class="chat"></button>
【问题讨论】:
标签:
css
position
alignment
sticky
【解决方案1】:
试试这个:
.chat {
width: 55px;
height: 55px;
position: fixed;
bottom: 20px;
left: 20px;
background: red;
border: 0;
}
position: fixed 是关键元素。
【解决方案2】:
您可以使用float: right; 联系到它。
html {
background: #ccc;
}
.chat {
width: 55px;
height: 55px;
position: sticky;
bottom: 20px;
right: 20px;
background: red;
border: 0;
float: right;
}
<button class="chat"></button>