简体   繁体   English

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

[英]Scrolling with a button which should have a fixed position

I am trying to get a button to work which should keep on scrolling.我试图让一个按钮工作,它应该继续滚动。 The website is http://mkg-praxisklinik-muenchen.de/ .该网站是http://mkg-praxisklinik-muenchen.de/ It is the green button "Termin vereinbaren" on the bottom left side.它是左下角的绿色按钮“Termin vereinbaren”。 This should stay sticky (fixed position) while I am scrolling the page.当我滚动页面时,这应该保持粘性(固定位置)。

The problem is that if the page is too short the button does not appear at all - as also on responsive designs.问题在于,如果页面太短,则按钮根本不会出现 - 在响应式设计中也是如此。

I have tried all the known css workarounds without success.我已经尝试了所有已知的 css 解决方法,但都没有成功。 Does anybody know of a javascript solution?有人知道javascript解决方案吗?

When using position: fixed, you need to set a position property like top,bottom,left,right使用 position: fixed 时,需要设置一个位置属性,如 top,bottom,left,right

In this case, all i did was add在这种情况下,我所做的只是添加

bottom: 50px;

and it works like you expected it to.它像您预期的那样工作。

Also, no need for margins when you are using positioning.此外,使用定位时不需要边距。

I also noticed you have a relative container, probably not the best way to go about a fixed element.我还注意到您有一个相对容器,可能不是处理固定元素的最佳方式。 I would remove the container all together.我会一起移除容器。

You can use bottom CSS rule in addition to position: fixed除了position: fixed之外,您还可以使用bottom CSS 规则

a.round-button {
    position: fixed;
    bottom: -150px;
    transition: bottom ease 0.5s;
}

And if you want the button to be expanded on mouse hover, you can try:如果您希望在鼠标悬停时扩展按钮,您可以尝试:

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

A simple demo一个简单的演示

More info about CSS bottom property关于 CSS 底部属性的更多信息

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM