【问题标题】:Using position: fixed with float value使用位置:用浮点值固定
【发布时间】:2014-06-13 06:44:37
【问题描述】:

我正在制作滚动到顶部按钮,我希望它出现在页面右侧的固定位置(大约在页面下方的 60%)。如果我使用相对或绝对,它只会随着页面的其余部分向上滚动。但是,当我使用固定位置来解决此问题时,该按钮会显示在页面左侧。我尝试使用带有百分比的左侧,但与浮动不同,它会随着您调整宽度而慢慢远离页面边缘。

这是我的代码(对混乱感到抱歉):

#upButton {
font-size: 15px;
text-align: center;
font-family: comic;
background-color: #FFFFFF;
width: 50px;
padding-top: 10px;
padding-bottom: 10px;
display: block;
position: fixed;
color: #000000;
float: right; 
top: 60%;

}

有没有人看到我可以更改以将按钮附加到页面右侧?

【问题讨论】:

  • 发布您的 html 或更好的 jsfiddle
  • 使用right 并放弃浮动。

标签: html css position


【解决方案1】:

将您的 CSS 更改为以下内容

#upButton {
    font-size: 15px;
    text-align: center;
    font-family: comic;
    background-color: #FFFFFF;
    width: 50px;
    padding-top: 10px;
    padding-bottom: 10px;
    display: block;
    position: fixed;
    color: #000000;

    right: 10px; /* or right: 10%; */

    top: 60%;
}

只需删除 float 并添加 right 代替

希望对你有所帮助...

【讨论】:

    猜你喜欢
    • 2013-11-30
    • 2015-03-28
    • 1970-01-01
    • 2014-10-01
    • 2019-04-10
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多