I created "Back-to-top" and "Go-to-bottom" buttons using HTML and CSS only as per different guidelines I found. I’m an amateur, so I thought this would be a simple fix.
As you can see (https://imthemoisturizer.com), the buttons are stuck on the lower-left corner of the website and, even though I’ve tried different solutions I can’t seem to make them position themselves on the lower-right corner, one on top of the other. For simplicity, I’ll just include the code for the "Back-to-top" button, since they’re basically identical (except for where they link to).
HTML:
On header.php I created this div:
<div id="top"></div>
On footer.php I added this:
<a href="#top" class="top"><img src="SVG image I want to show" alt="Boton subir" width="40" height="40"></a>
CSS:
This is the CSS code I included for positioning and appearance:
.top {
--offset: 50px;
place-self: end;
margin-top: calc(100vh + var(--offset));
/* visual styling */
background-color: #transparent;
width: 50px;
height: 50px;
text-align: center;
position: sticky;
bottom: 30px;
left: 85%;
right: 0px;
transition: background-color .3s,
text-decoration: none;
padding: 10px;
font-family: sans-serif;
color: #fff;
border-radius: 100px;
white-space: nowrap;
}
I’m out of solutions, so I really appreciate your help!
3
Answers
Do you want it to stay always on bottom left corner? Try something like this:
or just add to style attribute
also consider adding z-index if some other components are hiding these. Often dialogs by UI libs are placed at ±1000 of z-index, so added 900.
added divs to your site, here is screenshot. With CSS there may be overriding css rules etc. while code is tiny in this case and only used by this element, i would not worry to add inline style:
If you do not want the bottom button to be always there, please change the
position: 'fixed'
toposition: 'absolute'
You could wrap both buttons in a a parent div and give this wrapper a fixed position.
Both
<a>
will be on top of each other if you set adisplay:block
display property.Example
You can also add
scroll-behaviour:smooth
.This way you get a nice smooth scrolling effect.