This is the link to the codpen with the code:
https://codepen.io/gregelious/pen/zYmLGex
It is a restaurant menu with 3 categories(divs) as 3 separate boxes.
(in depth instructions here: https://github.com/jhu-ep-coursera/fullstack-course4/blob/master/assignments/assignment2/Assignment-2.md)
These were the instructions:
- When width >= 992, each box should take up a third of the width of the screen
- When width between 768 & 991, first two boxes take 50% of the width of the screen and the third box should take up 100% of the width on the next line
- When width < 768, each box takes up 100% of the width so there should be 3 separate lines
I gave the divs ids of "first" "second" and "third" and this is my css:
@media (min-width: 992) {
div {
width: 33.33%;
}
}
@media (min-width: 768) and (max-width: 991) {
#first, #second {
width: 50%;
}
#third {
width: 100%;
}
}
The sizes of the divs aren’t changing when I resize the browser window and I don’t know how to fix it. I got this assignment from a Coursera course and I rewatched the videos on media queries and other related stuff but I haven’t made any progress.
2
Answers
You need to put ‘px’ after your values in min and max width
I would recommend to use a container div to control the flex layout as shown in the next demo:
You have to make the layout work, that is what you do with
flex
properties (update, you need to set a unit tomin-width
andmax-width
properties, for examplepx
:min-width: 768px
)I also recommend to build your layout from small screens to larger screens (mobile first) and set only
@media (min-width)
css queries. Consider that larger media queries override previous small queries only if they are setted.Here is a working demo: