How come my responsive design functions properly when I test it using the mobile device tool, but fails to work when I manually decrease the browser size?

While testing my responsive design, I've noticed that using the toggle device tool in the Inspect tools of my browser produces the expected results. However, when I simply resize the browser window manually, the design does not respond as it should. Could this be a bug?

My implementation involves JavaScript to detect the screen size with the following function:

if(window.screen.availWidth > 1024 && window.screen.availWidth < 1200) { 
 ...
} else if(window.screen.availWidth > 1200) { 

... 

}

I've observed that the first condition

window.screen.availWidth > 1024 && window.screen.availWidth < 1200
is not satisfied when resizing the browser window, but works correctly when using the mobile tool in the inspect tools.

The specific mobile tool I am referring to can be seen here: https://i.sstatic.net/5FHOe.png

Could this discrepancy be a bug, or perhaps an issue related to the availWidth property?

Answer №1

window.screen.availWidth provides the device screen width, not the browser window width. When using the mobile tool, the browser mimics a mobile device, causing the webpage to consider the screen as mobile-sized regardless of the browser dimensions. On the other hand, window.screen.availWidth captures the monitor screen width and does not account for the browser window size.

You may find the window.innerWidth property more suitable in this scenario.

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

Restrict the hide/show functionality on a div to only operate within its specific radio group, without impacting the other radio groups within the form

I created a form with 3 radio groups that show different sets of divs based on the selection made. The issue I'm facing is that the current code hides radio content divs across all 3 radio groups. How can I fix this? My goal is to display all "Yes" c ...

The error message "Angular formGroup requires a FormGroup instance. Kindly provide one."

I used angular reactiveforms to create a form. The default data is successfully printed on the form, however, I am facing an error in the console that says "formGroup expects a FormGroup instance. Please pass one in." Can someone guide me on how to resolve ...

My goal is to display the products on the dashboard that have a quantity lower than 10. This information is linked to Firestore. What steps can I take to enhance this functionality?

{details.map((val, colorMap, prodName) => { I find myself a bit perplexed by the conditional statement in this section if( colorMap < 10 ){ return ( <ul> <li key= ...

How can I modify this code to be more responsive using float or relative positioning without introducing any errors?

I'm currently struggling to create a responsive web page that adjusts to any screen size automatically. Here is the code I have so far, including both HTML and CSS. What changes can I make to ensure the elements are properly placed regardless of the s ...

I cannot seem to receive the confirmation of success!

Trying to store user details in a database and display a success message that fades in. I have attempted some code, but unfortunately it's not working. Please help me out. Apologies if I am mistaken. Here is my register.php code: <?php require ...

Is there a way to prevent my Header links from wrapping during window size testing?

https://i.stack.imgur.com/YTc3F.png The image above showcases my standard header layout, while the one below illustrates what occurs as I resize the window. https://i.stack.imgur.com/re44T.png Is there a specific CSS solution to prevent the Text navLink ...

Using CSS to select a specific class within an attribute

Having trouble targeting a specific navigation item in a div using an attribute value in CSS. Here's the code I have so far: My goal is to target the navDepts class. HTML <div class="primary-nav" data-name="about"> <div class="sub ...

Tips for vertically aligning <p> and <div> elements without using the table-cell property

I am trying to align my text vertically in the middle using a ch-grid <div> (the circle color element). Is it possible to achieve this without specifying a display attribute for the <p> element? I plan to hide it by setting display:none initia ...

Inverting the order of vertices in a THREE.js face

I am seeking a way to reverse the order of vertices in faces within my geometry. For instance: // create geometry var geometry = new THREE.Geometry(); // create vertices geometry.vertices.push( new THREE.Vector3( 0, 0, 0 ) ); geometry.vertices.push( ...

What is the process of importing an HTML template into a Vue.js project?

I downloaded a template from the internet that I want to import into my vue project. This template includes HTML, CSS, and Javascript files of its own. How can I utilize vue-router to access the index.html file in this template without converting them into ...

Which file extension is superior for SEO: .html, .php, or .aspx?

Which file extension is more SEO-friendly: .html, .php, or .aspx? Or is an extension-less URL the best option for SEO? ...

Tips for incorporating automatic line breaks and setting a maximum column width in a table

Is there a way to set different maximum widths for table columns and enable automatic line breaks when entering text into the columns? Below is the code snippet I currently have: echo "<table border='1' cellpadding='10'>"; echo ...

"Can anyone explain why the text color of my font changes during a transition within a

Check it out on jsfiddle as well: https://jsfiddle.net/phmttrsh/ #btn { font-size: 16px; height: 34px; width: 120px; border: 1px solid #20ACB3; text-align: center; line-height: 34px; background-color: #20ACB3; color: #fff ...

methods for sharing real-time data between parent and child components in Angular versions 2 and above

When working with Angular, we are familiar with parent to child communication using the @Input decorator. However, the challenge arises when we need to pass dynamic data from the parent to the child component. Imagine having a 'name' property def ...

Want to learn how to create a draggable uploaded image on a canvas, similar to the functionality of Google

I have a question regarding the draggable feature in Canvas elements. I uploaded an image into the canvas and would like it to be draggable, similar to Google Maps. My ultimate goal is to enable zoom in and out functionalities as well. Is this achievable ...

Can values be extracted from a JSON object that is saved in a separate JavaScript file?

In my current project, I am creating unique tables dynamically and displaying them using JavaScript after making an AJAX call. Instead of writing individual code for each table, I'm looking to establish a standard layout where I can customize the desi ...

Preview of Hoverbox Caption

I'm working on a website using the Hoverbox image gallery (http://host.sonspring.com/hoverbox/) and I'm trying to include captions for each image preview that appears when hovering over the enlarged image. However, I am facing difficulty as I hav ...

How to create a Vue.js animated navbar with scroll opacity

I am looking to create a fixed navbar that changes opacity based on user scrolling behavior. Initially, I want the navbar background to be transparent and then transition to white as the user scrolls down the page. An example of what I am trying to achieve ...

How can I retrieve data from a JSON string using Javascript?

Here is the JSON data I am working with: { "head":{ "vars":[ "uri", "label" ] }, "results":{ "bindings":[ { "uri":{ "type":"uri", "value":"http://tematres.befd ...

Dealing with errors in Angular using dependency injection

I'm encountering an issue while attempting to inject $ http to the factory. I received the following error in Angular 1.6: Circular dependency found: $rootScope <- $http <- $exceptionHandler <- $rootScope <- $route Here is what I have b ...