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

Utilizing deployJava.runApplet for precise element targeting

After years of successfully maintaining an applet that utilizes the traditional: <script src="foo.js"></script> method for embedding a Java applet, we can no longer ignore the need for change. It's time to switch to: deployJava.runAppl ...

What is the best way to position a div in relation to a table header (th) but not inside it?

I'm trying to create a table header that displays a help text (div) when clicked on. However, the help div is causing the table header to be larger than the other headers. Below is the code snippet: #help_box { border-radius: 20px; ba ...

`In Firefox, the footer refuses to remain anchored at the bottom of the page`

After using the following code, my footer stays at the bottom of my page: In my vue project, #app serves as the container for my content and footer. #app { min-height: 100%; position: relative; } .footer { position: absolute; bottom: 0; width: ...

Retrieve specific form data with the help of jQuery

In a unique situation, I am dealing with a webpage that contains multiple forms and I am attempting to retrieve the data submitted in each form. Here is an example of the HTML code: <form name="form1"> <input type="text"> <input ty ...

Tips on making Material-UI Drawer compress other content when it is open

Seeking assistance from those familiar with CSS and Material UI! I'm currently working on implementing a Material UI Drawer component that doesn't just slide out over the top of the page content, but actually causes the page content to adjust aro ...

Can someone assist me in successfully incorporating a web font into a template?

After downloading a Wordpress template, I found the font used for h1 and h2 text to be difficult to read due to its slim design - Century Gothic. However, I prefer using Noteworthy, a font available on my Mac. I converted Noteworthy from OTF to web-font st ...

When it comes to @font-face, Chrome has no trouble detecting the font, but an issue

<style> @font-face { font-family : 'Avenir'; src : url("/fonts/Avenir999.otf"); } p.price a span { /*font-family : 'Avenir';*/ font-size : 45px; color: #889900; ...

The function document.getElementById is unable to select multiple elements simultaneously

I've been tackling a loading issue. I have a visible div, #loading, and multiple hidden divs, #message. I also have a JavaScript function. function loading() { setTimeout(function() { document.getElementById("loading").style.display = " ...

Fade in images using jQuery

I am having issues with fading in and out images using jQuery, it doesn't seem to be working as expected. I think there might be something crucial that I am missing. Take a look at the script below: var count = 1; setInterval(function() { ...

I am curious about how to implement overflow:hidden along with position:sticky in React.js

My attempt to address the white space issue caused by a navbar I created led me to try using overflow:hidden. The navbar is generated using the Header component, and I desired for it to have a position: sticky attribute. However, I realized that I cannot ...

Incorporating a Bootstrap input group within a <td> element of a table

Encountering an issue when attempting to include a bootstrap input-group-addon with the input field nested inside a <td> tag within a table. Once all necessary classes are applied, there appears to be some spacing between the sign and the input field ...

Different div elements are clashing with each other when it comes to hiding and

Having added multiple div elements with different IDs, I am facing an issue where clicking one div displays it while hiding the others. I am looking for a solution to prevent conflicts between the divs. Any suggestions on what might be causing this problem ...

When hovering over one div, both it and another div should be displayed simultaneously. The second div should continue to be displayed even when hovered over

I am looking to keep another div displayed when hovering over it - in this example, it says "hello." The div I want to remain visible is not a child element of the main div where I initiate the hover event. document.write("<base href=\"" + docum ...

What could be the reason for the lack of definition of the `pieceOfText

My latest project involves a fun guessing game centered around decrypting text, but I've hit a snag with a variable in my JavaScript code. This variable, known as pieceOfText, should be assigned a random piece of text from an array containing 3 encode ...

closer proximity of label to input field

I need help adjusting the distance between the text labels and input elements in my HTML form, which is designed using Bootstrap classes. Specifically, I want to reduce the space between the <label> and the <input> elements when they are displa ...

What causes the <td> element to extend beyond the boundaries of the <table>?

I need to add next and previous buttons to a <td> that has an asp:DropDownList. However, when I do this, the <td> ends up overflowing the width of the table. Here is the edited code snippet with the entire table included: <table class=" ...

Refresh page upon clicking the same state link in AngularJS using ui.router

Just received an interesting request from our QA team that seems a bit out there. Let's dive in: imagine you are already on the 'about' state/page within an angular-based app, and when you click on the 'about' state URL again from ...

Scroll Bar Menu (User-Controlled)

I'm looking for any libraries out there that can replicate or provide a similar horizontal scrolling menu to that of espn.com's homepage. I'm relatively new to jquery and feeling a bit lost on where to begin. I did some searching on Google, ...

Is it feasible to utilize Sublime Editor for building SCSS/SASS files? Learn how to compile SCSS/SASS with Sublime Editor

Despite numerous attempts, I have been unable to figure out how to effectively use the Sublime Editor for creating scss/sass files. ...

Internet Explorer automatically moves the cursor to the beginning of a textarea when it gains

When trying to insert "- " into an empty textarea, I am facing issues with Internet Explorer. While Firefox and Chrome work perfectly fine by inserting the text as expected, IE causes it to jump to the beginning of the textarea after insertion. Therefore, ...