Understanding the breakpoints in Media QueriesExploring the intric

I have established these breakpoints

    X-Small devices (portrait phones, less than 576px) 
@media (max-width: 576px) {
  body {
    background-color: red;
  }
}

 Small devices (landscape phones, less than 768px) 
@media (max-width: 768px) {
    body {
    background-color: blue;
  }
}

Medium devices (tablets, less than 992px) 
@media (max-width: 992px) {
    body {
    background-color: green;
  }
}

 Large devices (desktops, less than 1200px) 
@media (max-width: 1200px) {
    body {
    background-color: purple;
  }
}

 X-Large devices (large desktops, less than 1400px) 
@media (max-width: 1400px) {
    body {
    background-color: yellow;
  }
}

Why does the color always stay yellow when I resize the screen instead of changing with the specified breakpoints?

Answer №1

When setting max-width: 1400px, remember that this rule will also apply to smaller screens. To manage this, organize your CSS from largest to smallest screens so that the styles for smaller screens overwrite the values intended for larger ones. Alternatively, you can use

@media (min-width: value) and (max-width: value) { ... }

Here is an example of organizing styles from largest to smallest screen sizes:

@media (max-width: 1400px) {
  body {
    background-color: yellow;
  }
}

@media (max-width: 1200px) {
  body {
    background-color: purple;
  }
}

@media (max-width: 992px) {
  body {
    background-color: green;
  }
}

@media (max-width: 768px) {
  body {
    background-color: blue;
  }
}

@media (max-width: 576px) {
  body {
    background-color: red;
  }
}

You can also utilize the and keyword in media queries like so:

@media (max-width: 576px) {
  body {
    background-color: red;
  }
}

@media (min-width: 577px)
  and (max-width: 768px) {
  body {
    background-color: blue;
  }
}

@media (min-width: 769px)
  and (max-width: 992px) {
  body {
    background-color: green;
  }
}

@media (min-width: 993px)
  and (max-width: 1200px) {
  body {
    background-color: purple;
  }
}

@media (min-width: 1201px)
  and (max-width: 1400px) {
  body {
    background-color: yellow;
  }
}

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

Understanding HTML file paths

I'm a beginner here. I've encountered an interesting issue - the file paths for images appear correctly in my index.html file, but not for the background image specified in my css file. Both image files are located in the same directory: Root di ...

The design of the page is structured around Semantic-UI Grid, and unfortunately, the spacing between elements cannot

Currently, I'm in the process of developing a web application with the help of semantic-ui. The primary objective is to design a layout that comprises a sidebar along with a main content area. Initially, I assumed that utilizing grid would be the most ...

Is it possible to use a JavaScript string as a selector in jQuery?

So, my issue is with the following JavaScript code snippet: for ( i=0; i < parseInt(ids); i++){ var vst = '#'+String(img_arr[i]); var dst = '#'+String(div_arr[i]); } I'm wondering how I can proceed in jQuery to handle ...

Incorrect modal placement

I am new to CSS and currently working on customizing a modal window. My main issue lies with its positioning, especially when the browser resolution changes, causing a misalignment as seen in the screenshot. I would like to specify the width and height dim ...

Parallel with one <div> and subsequently another <div>

I have been challenged by HTML and CSS to embrace humility: Attempting to replicate the following design: Here is my effort: <div> <div style="width:800px;"> <div style="float:left;width:25%;background-color:red;">Facility #: COM ...

HTML - Customizing container with background color and ensuring minimum height of 100%

After creating a dynamic page using Bootstrap, I managed to add a sticky nav bar and footer. The navbar, footer, and page content are all in black color. I want the main content area to be white with black sides matching the background. Currently, I ca ...

"Uncovering the ways iOS disrupts background-size functionality

I am currently working on creating several marked images that will adjust in size to fit the length of their content. This functionality works well on most browsers, except for those on iOS devices like iPhone and iPad. Take a look at the image-link below ...

What is the best method for transforming an HTML file into an ICS (iCal) file?

Hello there! I am interested in converting an HTML file (website) to an iCalendar file (iCal). Is this even possible? If so, how can it be achieved? Does anyone have any ideas or recommendations on how to proceed? Thank you in advance! ...

Enhance the functionality of a directive by incorporating the ui-mask directive

Recently, I implemented a custom directive for an input field that adds a calendar icon with a datepicker to the input. I have used this directive in various sections of my application and now I am interested in incorporating ui-mask - another directive I ...

What is causing all webkit browsers to overlook the z-index in my code?

I have removed all unnecessary elements from my webpage to focus on reproducing a specific issue. HTML: <html lang="en-us"> <head> <meta charset="utf-8" /> <meta name="viewport" content="width=device-width, initi ...

Setting all lines within a textarea to have indentation

Can individual lines in a textarea be indented? I am using a handwritten font and the first letter on each line is getting clipped slightly. I have tried using padding and margin, but it has not solved the issue. Any suggestions? Thank you. Regards, Erik ...

Next.js: Out of the 3 card flips, only 1 experiences a malfunction

Gratitude to the community for always coming through with assistance. Your generosity and support are truly invaluable. As a first-time poster, I may overlook some details, so please bear with me. Embarking on my initial real project as a self-taught amat ...

Creating a custom loading spinner using HTML and CSS

I am looking to create a spinner using just the <input> element. The only element I can utilize is <input type="text" placeholder="Select Date" class="sel1" /> How can I use CSS to implement a basic spinner in this scenario? ...

The functionality of the click event attached with the addEventListener is

I have a unique project where I am developing a user interface for a paper-rock-scissor game. To create the UI, I included four buttons: "Start game," "rock," "paper," and "scissor." Initially, I wrote separate code for each button, which worked perfectly ...

Using JavaScript/JQuery, change relative or viewport sizes to fixed sizes when the page loads

Wishing you a delightful day. As I work on my website, I find myself relying heavily on viewport units like vw and vh for all measurements such as font size, padding, margin, width, and height. These units provide the flexibility needed to ensure that the ...

How can Watir retrieve the inner html content of a <span> element?

Currently, I am attempting to locate a navigation link by iterating through several spans with the 'menu-item-text' class. My objective is to compare the content within the span tags to determine if it matches the correct navigation control for c ...

Generate selection choices by looping through a JSON document

I am attempting to develop a search box that will provide autocomplete suggestions based on user input from a key-value pair in a json file. I initially thought using datalist would be the most suitable approach for this task, however, upon running the cod ...

Having an absolute element can lead to overflow causing a scroll

<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8" /> <meta name="viewport" content="width=device-width, initial-scale=1.0" /> <title>Document</title> <style> .wrap { ...

Apache causes HTML download tag to malfunction

I have an HTML file that includes the following code: <a href="/Library/WebServer/Documents/file.zip" download="file.zip"> Download here </a> When I test this HTML page on Chrome, it successfully allows me to download the file. However, when ...

Adjusting Bootstrap CSS Styles

After recently installing bootstrap 3.0 on my website and experimenting with it, I have a few questions. I am looking to customize certain aspects of the jumbotron (and other classes) in my personal .css file named "mycss.css". Here is the code I have add ...