Media Queries and min-width attribute in a browser

Media Queries....I'm not quite understanding min-width and the fact that it will work on a browser when you shrink it's size horizontally.   What is min-width actually a measure of.  Cause I feel like I would always be using max-width or even better an attribute called "width".

Just curious....I like for something to make sense in my head before using it regardless of whether it works
DaveKidAsked:
Who is Participating?
 
Julian HansenConnect With a Mentor Commented:
min-width means: Apply this style if the browser has at least a width of XXX

So lets say you want to make a <div> half the screen on larger screens but full on mobile.
Start by setting it for small screens
/* Set the default for small screens */
.myDiv {
   width: 100%;
}
/* Override the setting for screens 780px and larger */
@media (min-width: 780px) {
  .myDiv {
     width: 50%;
  }
}

Open in new window


So you can see from the above - we do a mobile first approach and override it with subsequent styles that come into effect at larger screen sizes.

You can read more about media queries here
0
 
Brandon LyonSenior Frontend DeveloperCommented:
Min-width is one of the many options for media queries. You can also use max-width for example (ie when the window has a maximum-width of XYZ px, apply these styles).

Here is some documentation with other forms of mediaqueries which can be used.

You can also combine multiple conditions into one media query. Ex: only apply some styles between yyy px and zzz px when the display orientation is horizontal...
0
 
DaveKidAuthor Commented:
Thanks.  The definition you gave at the beginning is what helped the most.  I completely get it now.
0
 
Julian HansenCommented:
You are welcome.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.