Guide to positioning elements in CSS to maintain a fixed location

While creating a Back To Top button, I set it to a fixed position using the position:fixed; property and also background-attachment:fixed;, but I'm still facing issues with its position changing when new data is inputted.

<html>
<head>
<title></title>
<style type="text/css">
a{
text-decoration:none;
color:black;
font-weight:bold;
}
a:hover{
border-bottom:1px solid rgba(0,235,255,0.77);
border-top:1px solid rgba(0,235,255,0.77);
}
ul{
list-style:none;
align-content:center;
}
li{
float:left;
font-size:20px;
padding-left:250px;
}
.background{
margin:0;
background-image:url("MWYLJ6SRDM.jpg");
background-size:1380px  auto;
background-repeat:no-repeat;
background-attachment:fixed;
background-position:center;
}
.topbar{
background-color:rgba(255,255,255,0.90);
height:50px;
width:100%;
color:black;
position:fixed;
z-index:1;
}
.backToTop{
background-color:rgba(240,0,255,0.72);
width:50px;
height:50px;
border-radius:25px;         
/*background-attachment:fixed;
position:fixed;*/
position:relative;
left:1295px;
top:600px;
}
</style>
</head>
<body class="background">
<div class="topbar">
<ul>
<li><a href="">Home</a></li>
<li><a href="">About Us</a></li>
<li><a href="">Contact Us</a></li>
</ul>
</div>
<h1>ABCDEFG</h1>
<h1>ABCDEFG</h1>
<h1>ABCDEFG</h1>
<h1>ABCDEFG</h1>
<div class="backToTop">
</div>
</body>
</html>

Answer №1

Adjust the CSS styling:

.backToTop{
    background-color:rgba(240,0,255,0.72);
    width:50px;
    height:50px;
    border-radius:25px;         
    background-attachment:fixed;
    position:fixed;
    bottom: 10px;
 }

position: relative is no longer necessary.

View the code on this Fiddle: https://jsfiddle.net/4f1zn1hv/

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

What is the functionality of the icon `<i>` in Twitter Bootstrap?

After adding an icon to a webpage, I noticed that it replaced the old, semi-deprecated <i> tag and instead used a customized image tag. It almost seems like <i ...> is just a simpler version of <img ...>. I'm curious about how this ...

Uploading images using the Drag and Drop feature in HTML

Hello, I'm having an issue with the drag and drop functionality. I want to expand the size of the input to cover the entire parent div, but for some reason, the input is appearing below the drag and drop div. Can anyone assist me with this? https://i. ...

Tips for aligning content vertically within a header:

I'm currently working on creating a responsive header with two columns. My goal is to have the button in the right column vertically centered. I am aware of the method for centering items using 'top: 50%; margin-top: -xy px', but my button ...

How to display text on a new line using HTML and CSS?

How can I properly display formatted text in HTML with a text string from my database? The text should be contained within a <div class="col-xs-12"> and nested inside the div, there should be a <pre> tag. When the text size exceeds the width o ...

What could be causing the sporadic functionality of my jQuery image resizing code?

Seeking help for an issue I am facing with my jQuery code. I have been trying to scale a group of images proportionally within an image carousel using jCarousel Lite plugin. However, the resizing code seems to work randomly and I can't figure out why. ...

Steps to eliminate the 'Edit Translation' text on Transposh

Attempting to eliminate the 'Edit Translation' text provided by Transposh to maintain the existing translations. Implementing CSS code like so: #transposh-3:nth-child(8){display:none;} and localizertextnode{display:none;} However, these styl ...

What is the method of obtaining the file name of the current template within a Jinja2 template?

If I have a code snippet like return render_template('index.html', users=users), is there a way to access the filename within the template without having to pass it explicitly from the view? ...

Using images in R Shiny with htmlTemplate: A step-by-step guide

In my current project, I have a file named template.html that I am loading using the code snippet below: https://i.sstatic.net/TipvS.png One issue I'm facing is including an image in this template.html file. Despite having the correct relative path ...

Displaying variables in JavaScript HTML

<script type ="text/javascript"> var current = 0; </script> <h3 style={{marginTop: '10', textAlign: 'center'}}><b>Current Status: <script type="text/javascript">document.write(cur ...

Spinning text within a circular rotation in CSS

Looking for guidance on how to center the "hallo" text inside a circle? Currently experiencing issues with the circle display in IE8 and Firefox. Any suggestions on how to fix this would be greatly appreciated. And here is the link to my code snippet: CSS ...

Advancing with Bootstrap 4: Progress Bar Evolution

It appears that Bootstrap 4 has introduced a new method for updating the progress of your progress bar. Aim: Dynamically update the progress bar percentage upon click <div class="progress"> <div id='progressBar' class="progress-bar" r ...

Having trouble with your CSS dropdown menu?

I've been struggling to implement a dropdown menu on my website following an online tutorial. Despite following the steps, I can't seem to get it working. It's frustrating because I want to move on to backend development. Hoping someone can ...

Is there a reason why the slide up feature is not working when I include the ul tag?

I need help with a jQuery code that will pull up/slide up an Html "p" tag when my page finishes loading. This snippet of jQuery code seems to be working fine: $(function () { $('.graybgc').slideUp(0); }); This is the HTML structure: <p ...

Is there a restriction on the number of stylesheets per page in Internet Explorer 8?

Discussing the limitations of CSS in a forum thread, a user shared insights: A user mentioned that Internet Explorer has is known to have a restriction of 4096 CSS rules per file. For more information, check out this source. Additionally, there might be ...

Angular has trouble displaying information across multiple HTML files

I have created an HTML file to display some data. The initial HTML file named disc-log.html looks like this: <div> <h2>Discs</h2> <jhi-alert></jhi-alert> <div class="container-fluid"> <div class=" ...

Expanding Material Ui menu to occupy the entire width of the page

I'm encountering an issue with a menu I created where I can't seem to adjust its height and width properly. It seems to be taking up the full width of the page. import React, { Component } from "react"; import Menu from "@material-ui/core/Menu"; ...

What could be the reason behind Google and Bing's mobile-friendly tests inaccurately flagging my site as non-mobile friendly?

Our website for resources is responsive and has been thoroughly tested on various real smartphones, including iPhone, Android, and Windows devices. It looks great on every phone we've tested it on. You can visit the resources website here: The site ...

In the Twitter Bootstrap documentation, which element is utilized for the sidebar?

I'm curious about the most efficient method for creating a sidebar like this using Bootstrap 4. https://i.sstatic.net/3eKwN.png From what I can see, it appears to be a custom component designed specifically for the documentation page, rather than ...

to return the value to default when deactivating the text input field

Implementing typeahead functionality on two input fields: <div class="form-group> <label class="control-label=">Product Code:</label> <input placeholder="Enter Value" type="text" class="form-control" ng-model="a.product ...

Styling pagination using CSS and jQuery

I am looking to display 3 sections in a simple, paginated way that mimics tabs. I am trying to implement the logic where when a pagination item is clicked and has the 'active' class, it should show the corresponding block. However, I am strugglin ...