Issue with Windows screen resolution affecting CSS dimensions

Encountering a strange issue – on Windows 10, some laptops have the default screen setting at 125%, making web pages appear too big since they were designed for 100% scale.

Any suggestions on how to address this? CSS? JavaScript? I'm unsure of the best approach.

Additional Information:

  • The web app is constructed with React.
  • Everything scales correctly at 100%
  • Other websites display correctly at 125% on the problematic laptop
  • Model of the problematic laptop: Lenevo yoga 730 15inch

Thank you

Answer №1

When working with CSS, you now have the option to utilize the following (although it is not yet standardized):

@media (-webkit-min-device-pixel-ratio: 1.25) { ... }

as well as

@media (-webkit-max-device-pixel-ratio: 1.25) { ... }

New in 2024: an alternative method is using the resolution property: https://developer.mozilla.org/en-US/docs/Web/CSS/@media/resolution

/* Minimum resolution */
@media (min-resolution: 1.25dppx) {
/* Maximum resolution */
@media (max-resolution: 1.25dppx) {

For Javascript implementations, you can consider utilizing:

window.devicePixelRatio > 1.25 ? doA() : doB()

For more information, please refer to:

-webkit-device-pixel-ratio - CSS: Cascading Style Sheets | MDN

Window.devicePixelRatio - Web API インターフェイス | MDN

Answer №2

Consider including a viewport meta tag within the head portion of your index.html file

<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">

Answer №3

To tackle this issue, one could leverage CSS resolution techniques.

/* Targeting a specific resolution */
@media (resolution: 150dpi) {
  p {
    color: red;
  }
}

/* Setting style for minimum resolution */
@media (min-resolution: 72dpi) {
  p {
    text-decoration: underline;
  }
}

/* Styling for maximum resolution */
@media (max-resolution: 300dpi) {
  p {
    background: yellow;
  }
}

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

Executing JavaScript in Selenium is a common task that can be accomplished by

Attempting to automate a process using Python and Selenium has been successful for me on various websites in the past. However, I am currently facing a challenge with executing JavaScript on a specific site despite finding tutorials online. https://i.ssta ...

Maximizing the potential of typescript generics in Reactjs functional components

I have a component within my react project that looks like this: import "./styles.css"; type InputType = "input" | "textarea"; interface ContainerProps { name: string; placeholder: string; as: InputType; } const Conta ...

Extracting a precise value from an array nested within another array

Within my nested associative arrays, I am trying to figure out how to splice a specific value. In a regular array, this is easily done with: arr.splice(arr.indexOf('specific'), 1); But when it comes to an array structure like this: arr['h ...

angularFire encounters difficulties when attempting to add information to Firebase

I am currently utilizing angularFire and attempting to save form data to firebase using $add. Any assistance on this matter would be highly appreciated. All the console logs are showing correctly, as I am able to view the data in the console. Apologies for ...

Run JavaScript code last before page unloads

Two pages are involved in this process. On the first page, there is a form that the user completes and then clicks on the submit button. After that, the code for the first page unloads, and the user is redirected to the second page. Actual Issue A loadin ...

Multer is not accurately processing the formData

When using Multer to handle Form Data, all fields, including image files, are left in the req.body object. Check out the code snippet below: In React: const state = { // other fields images: [], // array of image files }; let formData = new FormData( ...

Assigning websockets to a global variable may cause them to malfunction

I'm utilizing websockets in conjunction with JavaScript and HTML5. Here is the code snippet I am currently working with: <input type="text" onFocus="so = new Websocket('ws://localhost:1234');" onBlur="so.close();" onKeyUp="keyup();"> ...

JSON parsing encountered an unexpected token "J" at the beginning of the file, causing an error at line 4 of the mail.js API

I am struggling to identify the issue at hand and determine the root cause of the problem In my efforts to create a contact form, I have encountered an unexpected outcome. When I use console.log() on the FormData object, it shows an empty array and trigge ...

Why has my image suddenly increased in size?

As a mid-level backend developer, I pride myself on being able to solve problems independently. However, there is something about the act of writing out my issue that always seems to lead me towards a solution. It's like the concept of "rubber-ducking ...

Exploring Various JSON Arrays

There are 3 arrays provided below which I have no control over: groups_array = [ { "group" : "Mobile Test Region", "id" : "251" }, { "group" : "Mobile Demo Region", "id" : "252" } ] locations_array = [ { "location" : "M Testing", " ...

Inconsistencies in spacing among flex items with flexbox styling

https://i.sstatic.net/oT9dgpaA.png NavBar.js import React from "react"; import ReactDOM from 'react-dom'; import ReactDOMServer from 'react-dom/server'; import './NavBar.css'; function NavBar() { const heading ...

Breaking or wrapping lines in Visual Studio Code

While working in Visual Studio Code, I often encounter the issue of long lines extending beyond the screen edge instead of breaking and wrapping to the next line. This lack of text wrapping can be quite bothersome. I utilize a split-screen setup on my co ...

Showing database information from MySQL in a concealed div using PHP

My HTML code for the div is as follows: <div id="ticketupdates" style="display:none;"> </div> It then contains PHP code like this: <?php $sql2=" SELECT ticket_seq, CONCAT(CONCAT(notes),'<br><br><a hr ...

Tips on automatically centering an image within a div as it is resized

I'm currently working on a website that showcases cards featuring Discord users. Each card includes an avatar image within a div element, and when the user hovers over it, the image expands. However, I've noticed that as it expands, it shifts to ...

The contents of the $localStroage array do not align with those of the $scope array

I am storing objects in a `$localStorage` array for persistence. I have a check function to see if an object is already present in the array before adding or removing it (using `splice` if present, and `push` if not). However, after refreshing my page, th ...

The fonts have been successfully loaded on the local server, but unfortunately, they are

I am facing an issue with using custom fonts on my nextjs/tailwind project. The fonts are displaying correctly when I view the project on my local server, and even when I make a production build and run it locally. However, they do not show up when I deplo ...

A function that handles HTTP request and response

In order to decrypt data, I need to retrieve the encrypted response by hitting a specific URL and then use that encrypted data along with a key to decrypt it. Initially, I attempted to fetch the data response using POSTMAN, but all I got back was a series ...

What is the proper way to retrieve the value of the key "order" from this JSON object (containing semicolons in the name)?

Vijay Anand inquired about this particular matter yesterday, unfortunately, the discussion was closed before receiving any solutions: HTTP Response: { "entry": { "@xml:base": "https://API_PROC_SRV/", "@xmlns": "http://www.w3.org/2005/Atom", ...

What are the best practices for avoiding text wrapping around a DIV?

I have scoured this site extensively, searching for a solution to my problem. What I thought was a simple issue has left me frustrated after hours of trying to figure it out on my own. So, I've finally admitted defeat and turned to seek help... Here& ...

The web page is not being fully displayed by IE 8

I'm struggling with a simple code snippet that is causing trouble in IE8 but works fine in Chrome. Here is the code: <style type="text/css> #header-cont { width:100%; background:#0080c9; backgrou ...