1

Bootstrap includes some default media queries that look like this:

@media (min-width: 768px) {
  /* Pull out the header and footer */
  .masthead {
    position: fixed;
    top: 0;
  }

@media (min-width: 992px) {
  .masthead,
  .mastfoot,
  .cover-container {
    width: 700px;
  }

Why don't these include the max-width variable? Is that inherently implied by just using min-width, i.e. does CSS just simply "know" to take the highest min-width possible?

1
  • Maybe because the mobile application wants to take the maximum value for the width (logical for devices with a tiny screen). Commented Apr 16, 2014 at 13:35

2 Answers 2

1

It has to do with logic.
TL;DR: See it as if/else statements in you code. You only add the max if you want a max specified.


You can read it like this:

#Div{ color: green; }

@media (min-width: 992px) {
    #Div{ background: pink; }
}

This reads:
Make font->green, and also
if( min-screen-width at least 992px ) BG -> pink
If you would have maxwidth it goes with the same logic, only as maximum.

If you have both:

#Div{ color: green; }

@media (min-width: 500px) and (max-width: 992px){
    #Div{ background: pink; }
}

This reads:

Make font->green, and also
if( min-screen-width atleast 500px AND a maximum of 992px ) BG -> pink


Easy demo for max-width, make something tablet resolution only (asuming everything 1024+ is desktop):

    @media (min-width: 1024px) { /* ... */ }
Sign up to request clarification or add additional context in comments.

3 Comments

"if(min-screen-width<992)" - this doesn't really make sense. @media (min-width: 992px) reads if(window-width>=992px). And similar for your second snippet.
I almost changed it to 'window-width', but that might suggest that the javascript's window is used, but that's not. Its the resultion
My comment was really about the logic of your description, rather than whether it's screen or window... the width is "greater than or equal to 992", not "less than 992" (although you've also used "min" and "max" in the description as well, which is a bit confusing). (min-width refers to width of the window/viewport. min-device-width refers to the resolution/screen.)
1

There is a tendency to design for the smaller screen (ie. mobile) first and use media queries to target larger screens (ie. desktop) users. This is what you are seeing in the Bootstrap CSS.

The main stylesheet applies to the mobile browser (in fact all browsers). Then a media query is used to target slightly larger screens to apply specific rules:

@media (min-width: 992px) {

This targets window sizes greater than (or equal to) 992px (ie. whose minimum width is 992px).

There is no max-width specified here, so this applies to all large windows.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.