Discover the sleek and sophisticated method of shifting a div on scroll with Bootstrap

Is there a more elegant way to position the div in such a way that it stays on the top right while scrolling down on all screens, without causing the layout to be messy on tablets and other devices? I am currently using Bootstrap. You can see a DEMO here.

<!DOCTYPE html>
<html lang="en" ng-app="ShopCartApp">
  <head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <meta name="description" content="">
    <meta name="author" content="">
    <link rel="icon" href="../../favicon.ico">

    <title>Starter Template for Bootstrap</title>

    <!-- Bootstrap core CSS -->
   <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.2/css/bootstrap.min.css">
   <style type="text/css">
    body {
  padding-top: 50px;
}
.starter-template {
  padding: 40px 15px;
  text-align: center;
}
#divTotal{
  background-color: green;

}
   </style>


  </head>

  <body>



    <div class="container">

      <div class="row">
        <div class="col-md-8">
            <div class="panel panel-primary">
                <div class="panel-heading">
                    <h3 class="panel-title">Panel title</h3>
                </div>
                <div class="panel-body">
                    <div class="radio">
                        <label><input type="radio" name="optradio">Option 1</label>
                    </div>
                     <div class="radio">
                        <label><input type="radio" name="optradio">Option 1</label>
                    </div>
                    <div class="radio">
                        <label><input type="radio" name="optradio">Option 1</label>
                    </div>
                </div>
            </div>

            <div class="panel panel-primary">
              <div class="panel-heading">
                  <h3 class="panel-title">Panel title</h3>
              </div>
              <div class="panel-body">
                    <div class="radio">
                        <label><input type="radio" name="optradio1">Option 1</label>
                    </div>
                     <div class="radio">
                        <label><input type="radio" name="optradio1">Option 1</label>
                    </div>
                    <div class="radio">
                        <label><input type="radio" name="optradio1">Option 1</label>
                    </div>  
              </div>
            </div>

            <div class="panel panel-primary">
              <div class="panel-heading">
                  <h3 class="panel-title">Panel title</h3>
              </div>
              <div class="panel-body">
                    <div class="radio">
                        <label><input type="radio" name="optradio2">Option 1</label>
                    </div>
                     <div class="radio">
                        <label><input type="radio" name="optradio2">Option 1</label>
                    </div>
                    <div class="radio">
                        <label><input type="radio" name="optradio2">Option 1</label>
                    </div>
              </div>
            </div>

            <div class="panel panel-primary">
              <div class="panel-heading">
                  <h3 class="panel-title">Panel title</h3>
              </div>
              <div class="panel-body">
                    <div class="radio">
                        <label><input type="radio" name="optradio3">Option 1</label>
                    </div>
                     <div class="radio">
                        <label><input type="radio" name="optradio3">Option 1</label>
                    </div>
                    <div class="radio">
                        <label><input type="radio" name="optradio3">Option 1</label>
                    </div>
              </div>
            </div>
        </div>

        <div style="position:fixed;top:20px;float:right;right:0px;" class="col-md-4">
            <div class="panel panel-primary">
              <div id="divTotal" class="panel-heading">
                  <h3 class="panel-title">Total</h3>
              </div>
              <div class="panel-body">
                  <h2>Total</h2>
              </div>
          </div>
        </div>
      </div><!-- /.row  -->


    </div><!-- /.container -->


   <script type="text/javascript" src="angular.js"></script>
  </body>
</html>

Answer №1

<div class="container">

  <div class="row">
    <div style="position:fixed;top:20px;float:left;left:0px;"class="col-sm-8">

Answer №2

Unfortunately, there is no CSS workaround available to achieve a fixed positioning for containers on older mobile browsers. One possible solution is to use JavaScript to adjust the container's position during scrolling events. However, this method may not work smoothly on iOS devices as the onscroll event is only triggered after scrolling has ended, causing the container to jump to its fixed position instead of remaining in place.

Alternatively, there are advanced JavaScript libraries like iScroll 5 that can mimic the scrolling behavior by creating a fake scroll container, effectively addressing the issue mentioned above:

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

Tips for utilizing the Ant Design calendar through Selenium

I am currently working with an app that utilizes a calendar feature from Ant Design. Unfortunately, the date picker appears to be set as read-only, making it difficult for me to interact with using Selenium in Python. In attempting to work around this is ...

I would like to add an underline below the title

.thumb-text { position: absolute; width: fit-content; left: 50%; transform: translateX(-50%); } .thumb-text h3 { font-family: Georgia; font-size: 30px; color: black; font-weight: 900; } .thumb-text h3::after { content: ''; p ...

Seeking assistance with dilemmas related to jQuery (specifically kendo), .NET Web Service (asmx), and Json

After conducting extensive research on the subject, I was unable to find any satisfactory answers or complete examples. Since I have limited experience with jquery, I am in search of a straightforward sample that demonstrates what I'm trying to achiev ...

The impact of array splicing on data manipulation

I have a $scope array variable that I'm using to generate tabs on the front end, but I'm struggling with implementing a remove tab function. The code for removing tabs is as follows: function removeTab(index) { $scope.tabs.splice(index, 1); ...

Tips for displaying images uploaded by the user in a div using an input field

I have a file input field where users can select a file to upload. I want to use JavaScript to display the selected file after it has been uploaded by the user. How can I accomplish this? Does anyone know how to show the selected file in a file input fiel ...

When running `npm start`, I encountered the following issue: Error stating that module 'webpack-cli/bin/config-yargs' could not be found

I encountered an issue while running the command npm start which resulted in an error being thrown. $ npm start > <a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="ea89828b9a9e8f98b5dbdfb5d8aadbc4dac4da">[email protect ...

How can you utilize functions from external files within Angularjs controllers that are not classified as controllers themselves?

I have a unique scenario that I need help with. In my project, I am using a javascript file with three.js to render some models. To combine my frontend WebGL rendering with a backend library, I used Browsefiy to create a single js file named script.js. ...

Ways to display only a specific color in an image

Looking to work with an image that contains predefined color blocks? Take this example picture as reference: https://i.sstatic.net/QlwvY.png Is there a method to display only certain colored areas while keeping the rest transparent? Note that no edge pat ...

Having trouble signing out in Nextjs?

As a newcomer to Reactjs and Nextjs, I am currently working on developing an admin panel. To handle the login functionality, I have implemented the following code in my index.js/login page using session storage: const data = { name: email, password: pa ...

Sending a Javascript object to PHP for decoding as JSON can be accomplished by

After searching through numerous similar posts without success, I am still struggling to get this dynamic 2-dimensional JavaScript object to work. My goal is to pass it to PHP in order to insert it into a MySQL table. Utilizing an Ajax post seems to be the ...

AngularJS controller failing to deliver output

Just diving into the world of AngularJS, I've recently launched a new application but it seems like there's a crucial element missing when it comes to controllers. <!doctype html> <html lang="en> <head> <meta charset ...

Exploring the Possibilities of Message Embeds in Discord using JavaScript

My goal is to teach my bot how to scan the description of embeds for a specific phrase. After reviewing the documentation at https://discord.js.org/#/docs/main/v11/class/MessageEmbed?scrollTo=description, it appears that I need to implement code similar to ...

Preventing page re-rendering with redux when a condition is not met

I am currently working on a page that features a question paper with multiple options and a button to navigate to the next question. import Grid from "@material-ui/core/Grid"; import Typography from "@material-ui/core/Typography"; import React, { useEffec ...

Reorder the Polymer dom-repeat element following a modification in the child component's value

My Polymer dom-repeat list is working fine on the initial value sorting for the children. However, when I update a value within a child element, the sort order of the list does not reflect the changes. What is the best way to achieve this? <body> ...

The bottle framework has run into a problem due to exceeding the maximum recursion

I've encountered a maximum recursion depth error while trying to add a path for my web app. def runSQL(sql): db = sqlite3.connect('zadanie.db') c = db.cursor() c.execute(sql) data = c.fetchall() db.commit() c.close() ...

How to adjust the size of <img> in a Bootstrap carousel to fit the parent element using CSS

My webpage has a dynamic carousel feature where users can upload images, but I have no control over their dimensions. Despite some guidelines in place, it is uncertain if they will be followed. In my development tests, I have used three sample images: one ...

What could be causing the user object to be undefined in the NextAuth session callback function?

I'm experiencing an issue with NextAuth while trying to implement signIn with Discord provider. My goal is to add the userID into the session object using the session callback, but I keep encountering an error message stating: [next-auth][error][JWT ...

Restricting user access to a route based on its type to enhance security and control

Currently, I have a React, Redux, and Next.js app up and running. Within my redux store, there is a user object that contains an attribute called "type". Each type of user has its own set of "routes" they are allowed to access. I am looking for the most e ...

Removing HTML tags from Angular template bindings

My data list sometimes includes HTML elements <li *ngFor="let result of results"> <span [innerHTML]="result.question.title"> </span> </li> The issue with using innerHTML is that the HTML is parsed and rendered, affecting ...

Is there a way to change the projection of id in mongoose?

I have a microservice in Node.js, where I am using Mongoose to retrieve a document from my mongoDB. The document has multiple properties, but I only need to display 3 of them: The properties I want to display are '_id' as 'id', 'n ...