Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trialJasper Leenarts
13,830 PointsWhy do you set a min-width of 320px in this project?
What is the reason to set a min-width in this project?
@media (min-width: 320px) and (max-width: 568px) {
#menu ul {
display: none;
}
}
webdesignertroy
Front End Web Development Techdegree Graduate 14,718 PointsIn terms of cascading style sheets, my experience has been to set a min-width in cases where I have to write a similar rule that cannot simply be overridden by a prior rule. For instance, I may want to replace a horizontal menu with a vertical menu as my browser width reduces. I will set the horizontal menu to only display above the width of 320px. Under 320px, only my vertical menu will exist.
@media (max-width: 319px) {
#hmenu ul {
display: none;
}
#vmenu ul {
display: block;
}
}
@media (min-width: 320px) and (max-width: 568px) {
#hmenu ul {
display: block;
}
#vmenu ul {
display: none;
}
}```
ericb2
11,429 PointsAndrew Chalkley , It has been 4 months since this question was asked and none of the answers is definitive. Since you wrote the code in question, can you bring light to the situation? Thanks.
Andrew Chalkley
Treehouse Guest TeacherI picked the horizontal resolution of the iPhone.
ericb2
11,429 PointsAndrew Chalkley , Thanks for the amazing quick response, but the question isn't why you chose the the value you did, but why have a min-width criterion at all in this case? (as a corollary, why should something different occur at widths below 320px?)
Andrew Chalkley
Treehouse Guest TeacherActually, the min-width
is probably not needed. I've just added this to the head
of the HTML:
<meta name="viewport" content="width=device-width, initial-scale=1">
And tested it on an iPhone 6 (don't have one with 320px).
Good spot!
4 Answers
robertm
13,570 PointsSimply to hide an element of the website at that certain breakpoint
Geoffrey Emerson
18,726 PointsI was wondering the same thing. I think the instructor is doing the "min-width: 320px" out of some kind of habit. Experimenting with Chrome's Device Mode tool, you can see that both menus will be rendered on any device with a screen smaller than 320pxSuch as the LG Optimus One.
Also, neither menu style will be displayed for a device with a screen width of exactly 568px.
Tracy Trathen
10,468 PointsI changed the second media query's min-width to 569px and then both show within the respective widths with no issues.
Volodymyr Boretskyi
9,094 PointsI just set the max-width to 568px so nav tabs wont appear under 320px. But I am not sure if there is any device with resolution smaller than that.
Andrew Jensen-Battaglia
10,051 PointsAndrew Jensen-Battaglia
10,051 PointsBy specifying a min-width, the code inside the media query won't apply to resolutions below 320px wide. Not sure how necessary it is, but that's how the code should function.