使用应该具有固定位置的按钮滚动

时间:2014-08-15 19:37:56

标签: javascript css

我正在尝试使用按钮继续滚动。该网站是http://mkg-praxisklinik-muenchen.de/。这是左下方的绿色按钮“Termin vereinbaren”。当我滚动页面时,这应保持粘性(固定位置)。

问题是,如果页面太短,按钮根本不会出现 - 同样也会出现在响应式设计上。

我已经尝试了所有已知的css解决方法但没有成功。有人知道javascript解决方案吗?

2 个答案:

答案 0 :(得分:0)

当使用position:fixed时,你需要设置一个位置属性,如top,bottom,left,right

在这种情况下,我所做的只是添加

bottom: 50px;

它的效果就像你期望的那样。

此外,使用定位时无需边距。

我还注意到你有一个相对容器,可能不是解决固定元素的最佳方法。我会一起移除容器。

答案 1 :(得分:0)

bottom

外,您还可以使用position: fixed CSS规则
a.round-button {
    position: fixed;
    bottom: -150px;
    transition: bottom ease 0.5s;
}

如果你想在鼠标悬停时扩展按钮,你可以尝试:

a.round-button:hover {
    bottom: 0px;
}

A simple demo

More info about CSS bottom property