Desktop media queries are functioning properly, yet experiencing issues on mobile devices

I've come across this same question multiple times, but the solutions I've found so far haven't been helpful. My media queries are working perfectly on desktop, but they don't seem to take effect on three different android devices. It's as if the MQ isn't being recognized at all. I've tried using 'all', 'screen', 'screen only', and various other options, even changing my meta tag as shown below:

Meta:

 <meta content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1" name="viewport">
        <link rel="stylesheet" href="style_mini.css">

@media handheld, screen and (max-width: 48em) { some style }

This is my first website, and I'm quite confused about what I might be doing wrong.

After spending several hours testing, it appears that both of my devices believe they have a width of 960px and are using the media query for that width instead of the smaller MQ. Following the suggestions mentioned here: didn't yield any positive results.

html {} 
* {
 box-sizing: border-box;
 -moz-box-sizing: border-box;
 -webkit-box-sizing: border-box;
 -webkit-text-size-adjust:none;
 }
 body {
 font-family: 'Slabo 27px', serif;
 color: #3F4D59;
 background-color: #F2E9DE;
 width: 98%;
 margin: 0 auto;
}
.flex {
 display: flex;
flex-direction: column;
flex-wrap: nowrap;
justify-content: center;
align-content: center;
align-items: center;
}
...
 ... //rest of the CSS styles
 ...
  

Answer №1

Consider changing the measurement units in your max-size: try using px instead of em.

Below is an example of the media query code I always rely on for effective results on mobile devices:

@media screen and (max-width : 1024px) {
    /* Adjust the value 1024 to meet your requirements. */
}

Check out the W3schools reference for the em unit:

The em unit is relative to the font size of the element (2em equals twice the size of the current font)

It seems counterintuitive to base media queries on the font size of your document!

Answer №2

When working with media queries, it's important to note that they may not always function as expected. I recently encountered a situation where the results differed on varying screensizes, particularly around 30em. To troubleshoot and understand what's going wrong, try adding color: blue or color:red to elements like headings or the body tag to see changes reflected. You can also check out this demo on jsfiddle showcasing edited media queries in action.

Using handheld alongside other criteria could lead to unexpected outcomes, as each query will apply to any handheld device regardless of screensize. This might be confusing unless you have specific requirements for larger handheld devices. It's worth noting that using handheld in media queries isn't common practice.

In your CSS, it seems like there are repetitions in media queries targeting different screensizes. If you want a rule to only apply to a certain range, consider specifying both maximum and minimum values in the query. Alternatively, you can reverse conflicting properties from previous queries to ensure consistency in styles across different screensizes.

It's also essential to create a minimal, complete, verifiable example (MCVE) when seeking help on platforms like Stackoverflow. Simplifying your code will make it easier to spot errors and debug effectively.

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

PHP code isn't showing any posts

Context: I have implemented a PHP loop to generate a dynamic feed of my portfolio posts on my WordPress website. Issue: The first five posts are being displayed correctly, but the subsequent posts are not. I'm uncertain about the underlying cause and ...

HTML - Lists Not Displaying Properly in Numerical Order

My goal with HTML is to: Produce 2 Numbered Lists Nest an Unordered List within Each Ordered List and add elements inside Unfortunately, my numbering isn't displaying correctly. Instead of 1. 2. etc., I'm seeing 1. 1. Below is the code I am u ...

Updating the color of text when clicking on a link using javascript

I am facing an issue where I cannot seem to change the text color using JavaScript. The functionality to show and hide div tags is working perfectly, but changing the color seems to be a challenge. It's worth noting that there are no styles defined fo ...

Overlaying a div on top of an iframe

Struggling to make this work for a while now. It seems like a small issue related to CSS. The image isn't overlaying the IFrame at the top of the page as expected, it's going straight to the bottom. Here is the code snippet: .overlay{ width: ...

Title showcasing the index of a website

Help Needed: How to Remove "Index of /" Title on Google Search for Jobbulls Website Hello folks, I recently uploaded all the files for my website and when I search for my domain name on Google, it shows a page with the title "Index of /" listing out all t ...

Determine the number of rows in the Tabulator's table

Can anyone tell me how to retrieve the number of rows in a table created using Tabulator on a website? Is there a method like table.size or table.length that I can use for this purpose? The table has been initialized with the following code: table = new T ...

The integration of single page applications and <form> elements is a powerful combination in web development

Is there still value in using a <form> element over a <div> element when developing single page applications? I understand the purpose of the <form> element for traditional form submissions with a full page reload, but in the context of ...

How to apply styles to a child component using CSS modules in a parent component

For the styling of a Material UI component (Paper) within a Menu component, I am referencing this documentation. To style my components using CSS modules with Webpack as the bundler, here's an example: // menu.js import React from 'react'; ...

Utilizing the active tab feature within CSS

I am currently working with a detailed structure of bootstrap theme classes. Currently, I am in the process of designing a menu. This is the code snippet for the navigation bar design in Bootstrap- <div class="navbar navbar-fixed-top navbar-invers ...

Unlocking the secrets of extracting information from deeply nested JSON files

Struggling to grasp how to retrieve values from the nested JSON file format of TheMovieDB API for my University assignment. Trying to work with this specific file: This is what I have so far: httpConnect jParser = new httpConnect(); String json = jPar ...

Scroll horizontally through the number field in Chrome

I have configured a number input field with the text aligned to the right. Scenario: While testing, I discovered that selecting the entire text or using the middle mouse button to scroll within the input field allows for a slight leftward scrolling of ab ...

Element that hovers and floats

Just last week, I was working on coding a custom menu bar for my blog located at . However, when it came to adding social buttons, things went awry. It seemed like a float element issue! Despite my attempts to resolve it by adjusting widths and properties, ...

Utilizing jQuery for asynchronous image uploading

Just started learning jQuery and I'm having trouble uploading a jpg image file using the ajax method. It seems like it's not working properly. Can anyone guide me through this process? HTML <form action="" method="POST" enctype="multipart/fo ...

No visible changes from the CSS code

As I create a small HTML game for school, I'm facing an issue with styling using CSS. Despite my efforts to code while using a screen reader due to being blind, the styling of an element isn't being read out as expected. The content seems to be c ...

Merge the values of two select tags into a single textbox

There are two select Tags along with a text box included. <select name="select1"> <option>1</option> <option>2</option> </select> <select name="select2"> <option>1</option> <option>2 ...

The functionality of cloning in jQuery may encounter an issue where the text field remains enabled if the user selects an option labeled "other

Currently, I am working on a jQuery clone with my existing code and everything is functioning well. In the first scenario, if the user selects other from the dropdown menu, the text field becomes enabled. In the second scenario, when the user clicks ...

Chrome is experiencing a problem with anchor tags that have an href attribute set to a "blob:" URL and using a target of "_blank"

My current project involves developing a website feature that allows users to download a PDF version of a page. To achieve this, the generated HTML is rendered into a PDF on the server, which is then returned as a Base64-encoded PDF. This data is converted ...

Incorporate PHP form and display multiple results simultaneously on a webpage with automatic refreshing

I am currently in the process of designing a call management system for a radio station. The layout I have in mind involves having a form displayed in a div on the left side, and the results shown in another div on the right side. There are 6 phone lines a ...

The tag (p) is not located in a valid position

I am currently working with the following code snippet: <p class="pHelp"> xxxxx <a href="#components">Form components</a> yyyyy </p> This particular line is located within a long chain of nested HTML tags inside html/body/a/a/a/a/ ...

Correcting W3C validation issues is essential

I am encountering errors in my W3C validation process. Even though I have set <!DOCTYPE HTML> for my page, I continue to experience issues as shown in the image below. I have been trying to troubleshoot and resolve these errors without much success ...