Prevent elements from shifting when you zoom in on the page

After extensive effort and research, I have successfully discovered a method to resize page elements without distortion when zooming by utilizing "vh" and "vw" units instead of "px" or "em".

The current issue arises when zooming in causes the elements to shift towards the bottom-right corner of the page.

At 100% zoom:

https://i.sstatic.net/FosaC.png

Zoomed up to 500%:

https://i.sstatic.net/aJj6J.png

We need to prevent this unexpected movement of elements while zooming. Is there a CSS-only solution to address this?

Please refrain from testing the code on platforms like Stack Snippets or CodePen due to potential discrepancies. It is recommended to create separate HTML, CSS, and JS files for testing solely on Chrome. The necessary files can be accessed through the following link:

// JavaScript code snippet
var value = 0;
// Other variables and functions here...
.container {
  // CSS styles for container element
}

#progress-bar {
  // CSS styles for progress bar element
}

#progress-bar:after {
  // Additional CSS styles
}
<!doctype html>
<html lang="en">
    <head>
        <meta charset="utf-8">
        <title>load</title>
        <link rel="stylesheet" type="text/css" href="style.css">
    </head>
    <body>

        <div class="container">
            <div id="progress-bar"></div>
        </div>
       <script src="https://code.jquery.com/jquery-3.4.1.js"></script>
       <script src="script.js"></script>

    </body>
</html>

Edit: I have another project with stable behavior that avoids moving page content when zoomed. Feel free to request the full set of files and code if needed:

*{
  overflow: hidden;
}

.container {
  // Additional CSS styles for container
}

.number-ticker {
  // Styling for number ticker element
}

.number-ticker .digit {
  // Styles for digits within number ticker
}

Answer №1

Functional CSS:

.wrapper {
      display: flex;
      justify-content: center;
      align-items: center;
    }

    #loading-bar {
     position:absolute;
       justify-content: center;
      align-items: center;
       left: 10vw;
      top:  10vh;
      border: 0vh solid rgba(0, 0, 0, 0.8);
      width: 0vw;
      height: 2.1794850986238534vh;
      margin: 0vh 0 0 1vw;
      background: repeating-linear-gradient(-45deg, blue, blue 2.6525198938992043vh, darkblue 2.6525198938992043vh, darkblue  5.305039787798409vh);
      border-radius: 3vh;
      animation: fill 10s linear infinite;
      box-shadow: inset 0 0.6510416666666666vw 1.3106159895150722vh rgba(255, 255, 255, 0.2), inset 0vh 0.06510416666666667vw 0vh rgba(255, 255, 255, 0.3), inset 0 -0.3255208333333333vw 0.3931847968545216vh rgba(0, 0, 0, 0.2), 0 0.1953125vw 0.2621231979030144vh rgba(0, 0, 0, 0.3);
    }

    #loading-bar:after {
      position: absolute;
      width: 15.352430555555556vw;
      height: 2.6212319790301444vh;
      border: 0.1310615989515072vh solid rgba(13, 13, 13, 0.7);
      background: rgba(13, 13, 13, 0.7);
      border-radius: 3vh; 
      content: "";
      left: -1.5895669679487179vw;
      top:  -0.6553079947575361vh;
      z-index: -1;
    }

    @-webkit-keyframes fill {
      0% {
        width: 0vw;
      }
      100% {
        width: 14.885416666666666vw;
      }
    }

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

Creating a customized display on a webpage using XML and XSL to generate unique

Looking to utilize my xml file for generating various xsl pages. <movies> <movie> <name>Shark tank</name> <movie> <movie> <name>Tank Shark</name> <movie> ...

Despite the presence of data, MongoDB is not returning any values

I am currently working on a code that utilizes $geoNear to find the closest transit stop to a given GPS coordinate. The issue I am facing is that the result sometimes returns undefined, even though I have confirmed that the data exists in the STOPS collect ...

Moving data from the bottom of the page to the top

I am facing a situation where I have several foreach loops on a page that calculate the sum of variables. By the end of these loops, a specific variable contains data. However, I now need to display this data at the top of my page before the foreach loop. ...

The Google Maps listener event behaves as if it were clicked even though it is triggered by a mouseover

Two google.maps.event.addListener events are being added here google.maps.event.addListener(markerAcademicCenter, "mouseover", function (e) { markerIconAcademicCenter.url = 'MapIcons/Circle32.png' }); google.maps.event.addListener(markerAcade ...

Encountering TypeScript error TS2339 while trying to utilize a method from a different class within an event handler and binding the current

My development setup includes a service called DomService for all DOM manipulation tasks. Additionally, I have another service called ModalService that handles modal functionality. Within the ModalService, there are some events being bound, with a method ...

Challenges with retrieving all text records in a profile using ethers.js

Currently, I am facing difficulties in retrieving all ENS text records from a profile due to issues with the logic or potential approaches... With ethers.js v6, my current strategy involves fetching all the log data and then sifting through it. However, t ...

Is there a way to make a React Component to update and navigate to a specific position using react-sound

Currently, I am in the process of constructing an audio player utilizing react-sound. One feature I aim to incorporate is the ability to return to a specific position within the audio track. At the moment, this is my approach: goToVeryCustomPosition() { ...

Dropdown menu does not appear upon hovering over an item

I have been trying to create a menu that appears when hovering over #navigation-region. Below, you can see the HTML, CSS, and JavaScript code: The JavaScript is simply for adding the active class on the #navigation-region element. In the CSS, there is a s ...

Using Javascript and jQuery, populate a dropdown menu with options that are extracted from a different dropdown menu

These are my two <select> elements: <select class="js-select-1"> <option disabled>Starting point</option> <option>A</option> <option>B</option> <option>C</option> <option>D</op ...

The versatile nature of the flex-direction CSS property

I am attempting to customize the layout of the code available at https://codepen.io/rperry1886/pen/KKwbQNP in order to showcase the images in a horizontal sequence rather than vertically. Despite referring to resources on Flexbox like https://css-tricks.co ...

What steps can be taken to prevent relying on static file names in the code

Currently, my web application project is being bundled using webpack. The webpack configuration in use is outlined below: const HtmlWebPackPlugin = require("html-webpack-plugin"); const CopyWebpackPlugin = require("copy-webpack-plugin"); const path = requ ...

The functionality of Access-Control-Allow-Origin is not effective in Chrome, yet it operates successfully in Firefox

I'm facing an issue with my code in the HTML file. I have a second file that I want to load content from, and both files are located in the same directory <div id="mainMenu"></div> <script> $(function() { $('#mainMe ...

Can someone provide an easy way to determine the timezone based on a specific time?

Looking to determine the timezone based on a specific time, with no concern for the date but accounting for daylight savings. For example: get_timezone("15:00"); Is there an easy method to achieve this? ...

React JS alterations in circular word cloud

I have a unique project with a dynamic word cloud feature displaying random words. My goal is to customize the code so that the word cloud can showcase specific words from a list of my selection, like: let WordList = ['Apple', 'Banana' ...

Issue with Pagination functionality when using Material-UI component is causing unexpected behavior

My database retrieves data based on the page number and rows per page criteria: const { data: { customerData: recent = null } = {} } = useQuery< .... //removed to de-clutter >(CD_QUERY, { variables: { input: { page: page, perPag ...

Enhancing the appearance of the active menu item with HTML/CSS/JS/PHP

Here's the HTML code I have: <ul class="navigation"> <li><a href="index.php">Home</a></li> <li><a href="index.php?content=about">About us</a></li> </ul> As you can see, the content of the " ...

Tailored alignment of checkboxes and labels

I've designed a custom checkbox where the actual checkbox is hidden and a label is styled to look like a checkbox. Everything works fine, however, when I add a label, it doesn't align properly. Here's the link to the fiddle: http://jsfiddle ...

Unlocking the secrets of retrieving the URL query string in Angular2

I'm struggling to extract the URL query string returned by the security API, resulting in a URL format like this: www.mysite.com/profile#code=xxxx&id_token=xxx. My goal is to retrieve the values of code and id_token. In my ngOnInit() function, I ...

Maintaining the layout of two columns in Bootstrap 4, responsive design turns them into a single stacked

Currently using Bootstrap v4 with a two-column layout that splits the container in half. On larger screens, the items in each column display correctly. However, on smaller screens, Bootstrap shuffles the items from column 2 into column 1. I am looking to ...

Tips for displaying res.locals information in the console for debugging purposes using ExpressJS and Nodejs

Currently, I am delving into the world of Node.js and ExpressJS as a novice in this realm. My primary requirement is to log the entire or partial content of res.locals in my console for debugging purposes. Here's what I've attempted: var foo_ro ...