【问题标题】: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>

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-02-29
      • 2020-09-06
      • 1970-01-01
      • 1970-01-01
      • 2023-03-20
      相关资源
      最近更新 更多