Troubleshooting: @media query's max-width CSS property not functioning as expected

(The styling works on all browsers except Chrome)

I am trying to apply a specific style only when the browser width is less than 1400px

Unfortunately, using max-width is not producing the desired effect

@media only screen and (max-width:1400px)  {
.heading-left {
    left: -0.5%;
  }
}

When using min-width, the styling works as intended

@media only screen and (min-width:480px)  {
.heading-left {
    left: -0.5%;
   }
}

However, the style also changes when the browser width is above 1400px, which is not the desired outcome (I understand this is how it works, but the max-width is not working as expected)

Link to the Fiddle:

https://jsfiddle.net/j4Laddtk/

Answer №1

Have you experimented with including the viewport meta tag?

<meta name="viewport" content="width=device-width, initial-scale=1">

See this JSFiddle for reference

The viewport meta tag is essential for rendering responsive web pages, particularly on mobile devices. It plays a crucial role in media queries by providing information on the actual device width to the CSS.

Answer №2

Have you adjusted the zoom settings in your browser to a level other than 100%? If yes, please reset the zoom to 100% (Ctrl+MouseWheel)

Answer №3

Give this approach a try.

This method will focus on specific devices.

@media screen 
 and (max-device-width: 1400px) 
 and (min-device-width: 480px) 
{ 
   .heading-left {
    left: -0.5%;
   }

}

Targeting based on browser window size.

@media screen 
 and (max-width: 1400px) 
 and (min-width: 480px) 
{ 
   .heading-left {
    left: -0.5%;
   }

}

Answer №4

It's important to remember to position the @media queries following the declaration of your standard styles.

Answer №5

One common mistake is forgetting to specify the unit when setting a max-width:

@media only screen and (max-width: 1400)  { ... }

Be sure to include "px" after the numerical value to indicate the quantity of the max-width:

@media only screen and (max-width: 1400px)  { ... }

It's easy to overlook such simple details and spend hours troubleshooting the issue.

Answer №6

Solving this issue took me hours of troubleshooting with Bootstrap 3, only to discover that the missing piece was the meta viewport element in the header of each webpage.

<meta name="viewport" content="width=device-width, initial-scale=1.0">

For more information, check out this resource.

Answer №7

Success! I finally found a solution

@media only screen and (max-width: 700px) and (min-width: 400px) { 
    .heading-left { left: -0.7%; }
}

Answer №8

Haven't found a solution yet? Consider this important tip: when using media queries in CSS, remember to place them at the bottom of your stylesheets. This is because CSS rules are applied from top to bottom.

For example,

.container {
  color: white;
}

If you want the font color to be pink on screens smaller than 600px, make sure to write the media query below the original .container style like this:

.container {
  color: white;
}

@media only screen and (max-width: 600px) {
  .container {
    color: pink;
  }
}

If the media queries are at the top, the default white color will take precedence over the pink color specified in the media query.

Answer №9

Insert this into your head tag

<meta charset="UTF-8">
<meta name="viewport" content="width=device-width,initial-scale=1">

Answer №10

@media only screen and (max-width: 1000px) {
  /*Remember to include the meta viewport tag in your HTML*/
}

If the code isn't functioning as expected, you can try inspecting the elements in your browser by accessing the network tab in the developer tools and disabling the cache.

Occasionally, the issue may be related to the browser's cache.

Answer №11

I have a helpful tip to share regarding CSS files. When you have multiple CSS files and certain values aren't taking effect, make sure to check the order in which they are linked in the HTML document. If you have a separate CSS file for media queries, it's recommended to place it at the bottom of all other CSS links to ensure it takes precedence.

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

Adjust the height of images to be consistent

I'm currently working on creating a grid layout with 4 images in a row using DaisyUI card component. However, I've run into an issue where there is white space at the bottom of some images due to varying image heights. Is there a solution that wo ...

React frontend communicating without backend server

Is it possible to send a message between two frontend users on web applications built with React? ...

What is the best way to attach two separate event listeners to a single button?

I'm attempting to have one button trigger two different functions, but I haven't been successful so far. I tried adding the second event listener as indicated by the // part, but it didn't work. The two functions should be executed sequentia ...

Empty space encompassing the entire sheet

While developing my website, everything seemed normal until I added a CSS document to my HTML page. Now, when we open the website , there is a white space around the entire page. I attempted to set the body class to container-fluid since I am using Bootst ...

Stopping horizontal scrolling in Material-UI Autocomplete/Popper: A troubleshooting guide

I am currently working on incorporating the Material-UI Autocomplete component, and my goal is to have each option label show an icon along with some text. The challenge I'm facing is that I only want the popper element to be the width of the text inp ...

When a PHP-generated child element is clicked, jQuery fails to detect it

I'm currently developing a website where I need to dynamically display buttons based on database content. These buttons, when clicked, should send a request to the database and update the page content accordingly. My approach involves using Ajax and ...

The alignment of unordered lists can be modified

Having a bit of an issue with positioning/resizing UL lists. I have <li> tags with varying heights but the same width. I want to adjust their position so there is no blank space between them when resizing the window, ensuring they are always close t ...

Looking to align a radio button in the middle of an inline-block?

Is it possible to center a radio button within an inline-block? I have provided a demo on JSFiddle that displays the current layout and how I envision it should appear. Check out the demo here Here is the code snippet in question: <span style="widt ...

Different ways to adjust the appearance of table borders in HTML

I find myself at a standstill, hence why I am reaching out with this question. This Table presents itself with various border sizes and colors, along with similar complexities in the background of its cells. Could anyone provide me with guidance on how t ...

implementing a collapsible sidebar menu with CSS tables

I am working on a layout with three columns created using css tables to perfectly fit the browser window. The first column serves as a menu and I want it to hide or move to the left when clicked, allowing the middle column to expand into its space. However ...

The list style of Bootstrap Select Drop Down isn't vertical

Has anyone encountered an issue with bootstrap-select where the options in a drop down box are not vertically listed? <script src="{% static 'risk_parity/js/jquery-3.2.1.min.js' %}"></script> <script src="{% static 'r ...

Is there a way to incorporate text at the end of a row in HTML?

I have a photo and some text on my website. The photo is displayed on the left side, while the text appears nicely on the right side. Now, I am looking to include an additional block of text below the existing text. How can I accomplish this? What steps ...

Detecting unutilized space in a collection of divs with varying sizes using JavaScript and CSS

To better understand my issue, I created a StackBlitz demo: https://stackblitz.com/edit/angular-aqmahw?file=src/app/tiles-example.css Screenshot My tiles can have four different widths (25%, 50%, 75%, 100%). The tiles must fit on only two lines, so if a ...

Applying a CSS class to a jeditable input field

Is there a way to apply a simple class tag to a jeditable input field? The developer's instructions on their website () suggest using the following code snippet under "How to style elements?": $('.editable').editable('http://www.exampl ...

Using v-model in Vue 3 will result in modifications to the table class in Bootstrap 5

Below is a snippet of the code I wrote: <table class="table table-striped"> <tr class="table-dark"> <th>#</th> <th>Column 1</th> <th colspan="3">Column 2</th> </tr> <tr ...

What is the best way to ensure the image and card maintain the same size ratio in React Bootstrap?

One of the challenges I encountered involved a vertically aligned card group containing a card with an image: https://i.stack.imgur.com/w9Jkf.jpg This is the React code snippet that was causing the issue: import React from 'react'; import { ...

The update of the attribute in jQuery on a checkbox is not causing the change event to trigger

I am working on a feature where there are multiple checkboxes along with a status box that indicates if at least one of the checkboxes is checked. Additionally, I have included a Check All/None checkbox that can toggle all the checkboxes. However, althoug ...

I developed a compact application utilizing Node.js in tandem with Express framework

There is an issue with the GPA calculator app built using Node.js and Express. It works fine for a single user, but when multiple users try to use it simultaneously, the scores are being combined, resulting in incorrect values. I need to create an app that ...

Replace the bullet icon with a double quote symbol

My HTML List needs a different look - I want to change the bullet icon into a double quote icon. A website that I found interesting is this one. Here's the CSS code I have: .listStyle li:before { list-style: none; content: "\00BB"; } < ...

Using Roboto Typeface in Cascading Style Sheets

I am currently working on implementing the "Roboto" font in my Prestashop website. The design files I received are in .psd format, and the graphic designer used fonts "Roboto Medium" and "Roboto Regular". To clarify, if I want to use Roboto Normal, can I s ...