The @media query appears to be functioning properly, however, it is not producing the

Conducted a basic test on @media queries to determine functionality:

Visit the test page here

I have set up a @media query in test.css that is supposed to change the background color from black to red on landscape tablets (1024x768). The CSS and XHTML are both valid, but for some reason, the background remains black in Firefox using Chris Pederick's Web Developer Extension -> View Responsive Layouts, as well as in the transmog.net iPad emulator (I do not own an iPad).

If anyone can shed light on why it’s not functioning properly, I’m excited to dive deeper into media queries.

Answer №1

First and foremost, these breakpoints are unparalleled

 @media (min-width:320px) { /* smartphones, iPhone, portrait 480x320 phones */ }
 @media (min-width:481px) { /* portrait e-readers (Nook/Kindle), smaller tablets @ 600 or        @ 640 wide. */ }
 @media (min-width:641px) { /* portrait tablets, portrait iPad, landscape e-readers, landscape 800x480 or 854x480 phones */ }
 @media (min-width:961px) { /* tablet, landscape iPad, lo-res laptops and desktops */ }
 @media (min-width:1025px) { /* big landscape tablets, laptops, and desktops */ }
 @media (min-width:1281px) { /* hi-res laptops and desktops */ }

For your specific scenario, employ this media query instead

 @media (max-width:1024px)  {
html, body { 
    background-color: #f00;
    color:#000;
     }
}

Answer №2

Your media query needs to be corrected; using max-device-width is not valid, you should use max-width instead.

<!DOCTYPE html>
<html>
<head>
    <title>Page Title</title>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <meta name="viewport" content="width=device-width; initial-scale=1.0; maximum-scale=1.0; user-scalable=0;">
    <meta name="apple-mobile-web-app-capable" content="yes" />
    <style type="text/css">
        html, body {
            height: 100%;
            font-size: 12px;
            text-align: left;
            margin: 0;
            padding: 5px;
            background-color: #000;
            font-family: verdana,arial,geneva,helvetica,sans-serif;
            color: #fff;
            text-align: center;
        }
        /* For iPad and other tablets in landscape mode */
        @media screen and (max-width: 1024px) {
            html, body {
                background-color: #f00;
                color: #000;
            }
        }
    </style>
</head>
<body>
    <h1>Why isn't the background red on iPad in landscape mode at 1024px width??</h1>
</body>
</html>

Answer №3

It appears that utilizing "@media only screen and (max-width: 1024px)" is effective as well.

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

Guide on filling accordion with data from Firebase

I have been working on a web page that retrieves data from my Firestore collection and is supposed to display each document with its corresponding fields. The goal is to populate the accordion with data from Firebase, but unfortunately, nothing is showing ...

Rails will provide JSON responses rather than HTML

My ruby on rails web app is currently set up to return HTML, but I want it to function as a web service and return JSON instead. I would like this to apply to all CRUD methods, so that the entire page is rendered as JSON. So far, I have only been able to a ...

How to precisely position a glyphicon in the center of a navbar

I am struggling to center my glyphicon (with its accompanying text) in the middle of the navbar, ensuring it remains centered and responsive even when the window is resized. I want to prevent it from scrunching together when the window is narrow and avoid ...

Can Angular be used to send form data to an external URL?

Let's take a look at an example with some code: <form method="post" action="URL"> <input type="text" name="first name" /> <input type="text" name="last name"/> <input type="submit" value="Submit" name="submit"/> < ...

Having trouble with adding data from an array of objects to an HTML element using jQuery's each method

I am currently facing an issue with looping through an array of objects using $.each in jQuery and trying to append the values to an <li>. Here is the relevant jQuery code: $(".sidebar").empty().append("<div>" + "<h5>Student Info</ ...

What is the best way to activate materialise pop-up menus in a React application?

Looking to enhance my React app by adding a NavBar with dropdown functionality. Here's the code snippet: <ul id="dropdown1" className="dropdown-content"> <li><NavLink to="/create">Create lesson ...

Enhancing User Experience in VueJS with Pug Templates and Transitions

Managing multiple 'pages' of content within a multi-step process can be challenging, especially when trying to incorporate VueJS's transition feature for a carousel-like slide in/out effect. The contents being transitioned are stored in sepa ...

What is the best way to incorporate an array of images into a swipebox gallery?

This is my unique HTML code: <div class="profile-gallery"> <div class="profile-gallery_top js-bigImg"> <a href="img/bigImg1.jpg" class="swipebox"> <img cla ...

What is the best way to enclose a handlebars expression within a span element while also making the span clickable?

In the button, the datePick string is a computed property that can be clicked on to trigger an event. However, clicking outside the datePick value inside the button does not trigger the event. Even after wrapping it inside a span and setting width: 100%, ...

The battle between percentages and pixels in fluid design

I am looking to create a flexible layout and would like to achieve the following: width:100%-200px; This means having a div that contains content, referred to as div id="content", with a fixed margin on each side. I have attempted to place the div id="co ...

(Material UI version 5) Custom global style enhancements

One of the examples in MUI is the Global style overrides: const theme = createTheme({ components: { // Name of the component MuiButton: { styleOverrides: { // Name of the slot root: { // Some CSS fontSize ...

Events related to key press timing in HTML 5 canvas

Currently, I am developing a game similar to Stick Hero for Android using HTML5. I am working on the code that will capture the time of key press (specifically the right arrow key with ASCII 39) in JavaScript and expand a stick accordingly. <!doctype h ...

Align two spans vertically in a div using Bootstrap

Struggling to create a left-hand side navigation card with Bootstrap and Bootstrap icons. The goal is to have the page name on the left and an icon on the right, but vertical alignment is posing a challenge. Take a look at the code snippet below: <b-li ...

Make the div stretch to the entire page size while keeping the existing content intact

I have a concept in mind where I want a clickable circle on the top left corner that expands to full page when clicked. Using a scale, I was able to achieve this effect. .hover.opened { transform: scale(1); transition: all 0.5s ease-out; overf ...

The HTML textarea is not updating properly when using jQuery's keypress event

I am facing an issue with my forms on a webpage, each containing an html textarea: <textarea name="Comment" class="inputTextArea">Hello World!</textarea> There is a javascript event handler that automatically submits the fo ...

Combining additional buttons to function as a single unit

Currently, I have a setup with two buttons that add and remove contacts, along with a third button that retrieves a user's geolocation. Is there a way to make the newly added buttons automatically incorporate the geolocation function? Essentially, whe ...

How asynchronous problems can affect the order of execution in jQuery when using $.load() with a bootstrap modal

Encountering a peculiar issue with the order of operations in jQuery. The code functions flawlessly in Internet Explorer 9 and 10, but fails to work in IE11, Firefox, and Chrome. It triggers the opening of a new window, but the load() function does not exe ...

JavaScript Popup prompting user on page load with option to redirect to another page upon clicking

Can a JavaScript prompt box be created that redirects to a site when the user selects "yes" or "ok," but does nothing if "no" is selected? Also, can this prompt appear on page load? Thank you! UPDATE: Answer provided below. It turns out it's simpler ...

The onclick event seems to be malfunctioning on the website

My goal is to implement a modal box that appears when a user clicks a button and closes when the user interacts with a close button within the modal box. I have created two functions for this purpose: check() : This function changes the CSS of an element ...

Tips on how to add information to the following <li> tag

I'm trying to append data to the closest li element when clicked using jQuery, but I've tried next, parent, closest, find and nothing seems to be working. Here is a link to my jsfiddle showcasing the issue: http://jsfiddle.net/kT3Rb/47/ This i ...