Uncertainty with CSS media queries: untangling the confusion of overlap and ordering

I'm struggling with my media queries and customizing a purchased responsive WordPress theme.

As the design reacts differently to various screen widths, I find myself using overlapping media queries for adjustments when issues arise.

Instead of having a clear sequence of media query sizes, I have a jumbled mess that complicates things further.

In my CSS, you can see how complex it has become:

@media only screen and (max-width: 961px) {
    /* up to 961px */


@media only screen and (min-width: 885px) and (max-width: 961px) {
    /* 885px up to 961px */


@media only screen and (min-width: 768px) and (max-width: 884px) {
    /* 768px up to 884px */


@media only screen and (min-width: 480px) and (max-width: 767px) {
    /* up to 767px */


@media only screen and (max-width: 550px) {
    /* Resizes top nav text for smaller screens*/


@media only screen and (min-width: 481px) and (max-width: 550px) {
    /* Adjusts location of search bar */


@media only screen and (max-width: 565px) {
    /* Toggles Justified Image Grid for home page buttons */


@media only screen and (min-width: 566px) and (max-width: 721px) {
    /* Toggles Justified Image Grid for home page buttons */


@media only screen and (min-width: 722px) and (max-width: 902px) {
    /* Toggles Justified Image Grid for home page buttons */


@media only screen and (min-width: 903px) {
    /* Toggles Justified Image Grid for home page buttons */

It's quite messy, right? I'm still learning, so please bear with me :)

The main issue now is that despite defining specific queries for the Justified Image Grid, they are not behaving as expected. Could the problem be related to the complexity of other queries, even if they don't mention the image grid?

I'm open to suggestions on managing queries in these situations, common in web development projects...

EDIT: Here is the test page link: I want to display only one image grid element at a time.

Thanks! Jon

Answer №1

To simplify things, consider removing the min-width portions from queries with both a min and max. Utilize only max-width queries and arrange them from largest to smallest in order.

@media only screen and (max-width: 961px) {
}
@media only screen and (max-width: 884px) {
}
@media only screen and (max-width: 767px) {
}

These will automatically override each other as the screen size decreases past each respective setting.

In my experience, focusing on max-width settings and adjusting them accordingly has worked well. Ensure you set them up correctly for best results.

If you are experiencing issues, it could be due to overlapping conditions in two queries with similar size parameters. The query located last will take precedence, potentially leading to unintended outcomes.

From personal experience, using purchased WordPress themes may not always meet your expectations. Customizing themes like _s or one of the twenty___ themes that come with WordPress can often provide better results. Purchased themes are typically designed with specific intentions or plugins that may not align with your own needs.

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

Activate the display by utilizing the getElementsByClassName method

In my design, I'd like to have the "Don't have an account?" line trigger the display of the .registrybox class when clicked. However, the script I've written doesn't seem to be working as intended. The script is meant to hide the .login ...

Disappearing Div Dilemma: The Mystery of the Responsive Design

I am currently facing an issue where two div elements (`.left` and `.right`) are not displayed vertically when the width value is less than 800px. Strangely, the `.left` div disappears when I try to adjust the width. I have shortened the code for clarity. ...

Revamping Existing Styles: Making a Statement with `:after`

In my asp.net mvc application, I am facing an issue where the * symbol, representing a required field, and the ? symbol, representing help, are not both being displayed. The ? symbol seems to be overriding the * symbol, resulting in only one symbol being s ...

Tips for aligning thumbnail text to the right on a small viewport with Bootstrap

Here is a visual representation of the standard thumbnail layout Once the viewport reaches the small size, the layout should switch to this design: Bootstrap only shrinks the container by default, as demonstrated in this jsfiddle: http://jsfiddle.net/32 ...

What is the best way to send a JavaScript variable to PHP for storage in a WordPress database?

I am currently in the process of developing a star rating system within Wordpress and am looking to store the rating data in the Wordpress database. To achieve this, I have saved the star rating PHP code as a template within my Wordpress theme folder. Belo ...

The website's behavior varies across various web browsers

I am currently working on a website with a full-screen video background and additional JavaScript components. Website : www.omod.biz/omoddemo Unfortunately, the website's performance varies across different browsers. It runs smoothly on Chrome and I ...

Trouble arises when attempting to bind a JavaScript event with an innerHTML DOM element

I am currently dealing with a complex issue on how to bind a JavaScript event to an innerHTML DOM element. The scenario involves having a div with an input checkbox inside it, along with some pre-existing JavaScript event bound to that checkbox. Additional ...

The properties of JavaFX in the CSS file are not recognized by Eclipse, showing an error message as "unknown property"

After installing Eclipse and downloading the OpenJFX SDK, I encountered an issue where Eclipse marked all -fx- properties in the .css file as warnings with the message "unknown property". Surprisingly, my JavaFX projects still compiled and ran smoothly, ...

Unable to resize icons within bar-footer

My footer has a bar: <div class="crop modal"> <div class="crop-center-container"> <div class="crop-img" ng-style="{width: width + 'px', height: height + 'px'}"></div> </div> <div cla ...

I'm having trouble getting rid of this stubborn loader on the website

I am currently utilizing the following template: . My objective is to eliminate the preloader progress bar that displays the loading progress of the page in percentage. The files associated with this preloader are as follows: Loader CSS File - www[dot]the ...

Items are overflowing the flex container, exceeding its boundaries

I've experimented with the width property, flex, flex-basis, and flex-shrink, but so far nothing seems to be working. I can't seem to pinpoint where the mistake lies in the code. I wanted to include the code snippet here, but it's throwing ...

Tips for creating a margin on an HTML button's background color

My bootstrap button has dimensions of 46 x 96px and a border radius of 22px. When hovered, I would like the background color to only extend up to 40 x 90px, without filling the entire button. I understand this can be achieved using a box-shadow, but since ...

Create two div elements containing responsive images using HTML and CSS

Can someone assist me in creating responsive DIVs with images inside? Currently, the second div is appearing below the first one, and I'm struggling to make them scale based on mobile and tablet screen sizes. Here is the code snippet: .new_ba ...

The variable 'DataList1' is not recognized within the current scope

Upon loading a page, I encountered the following error message: 'The name 'DataList1' does not exist in the current context' Below is the code snippet where the issue occurred: listviewvideos.aspx.cs private void BindGrid() { ...

Looking to connect a dropdown to an icon that has the type "button"?

I am facing a challenge with an icon placed on a Twitter Bootstrap container. My goal is to click on this icon and have a dropdown menu appear, offering various options that link to different websites. Currently, I am able to display the dropdown menu, but ...

creating div elements that are confined within the visible area of the browser

I'm currently attempting to append a specific number of div elements to the body without altering the width or height of the body itself. Essentially, I need the new divs to remain within the viewport. Here is the code I'm working with: divAmou ...

The SVG icon displays properly when viewed on a local machine, but is missing when the website is deployed

Something strange is happening with my SVG sprites. Everything seems to be working fine when I test my code locally, but once deployed on Firebase, one of the SVG images fails to appear. What could be causing this issue? Below is the code for two SVGs: sm ...

Issue with applying className to ToggleButton component in React with Material-UI

When utilizing React and Material UI, my goal is to efficiently apply styles to a group of ToggleButtons. At the moment, I am only able to specify the style prop for each individual ToggleButton in order to achieve the desired styling. I am attempting to ...

Please select the links located beneath the see-through triangular or polygonal shapes

Review the code snippet provided at the following link: http://jsfiddle.net/q8Ycz <div style="background-color: red; width: 200px;" onclick="alert('behind')"> <div><a href="test">test test test test test test test test test ...

`` I am experiencing a problem with CSS display block in Internet Explorer

Looking to implement a basic tab menu using a combination of tables and div elements. The goal is to have the tabs switch styles when clicked, giving the appearance of being toggled, while also swapping out the corresponding content in separate div blocks ...