I'm trying to make a responsive card layout as shown in the picture.
Currently what I'm doing is creating separate layouts for computers, tablets, and mobile devices. Then with the help of media query
I set the display property of the other two views to display: none
.
Example: If I'm in Computers view, the computer's card layout will not have the display set to "none", while the other two computers' display will be none
.
This works, but results in a lot of redundancy. There is a way to achieve all three layouts using Flex or Grid.
Please guide me.
You don't have to set
display: none
every time you want a certain design for a screen size. Media queries brings something called breakpoints where you can specify the width of the screen (e.g.min-width: 768px
). For mobile screen sizes, just put the css under media queries and setmax-width: 600px
. Additionally, you can use theorientation
attribute to differentiate between landscape or portrait mode.More information about queries and screen sizes
Make sure to follow
MDN Guidelines
Flex makes this easy.
Depending on the screen width, you can add media queries as shown below and you can adjust the box width and max width to resize the box.
You can viewhttps://jsfiddle.net/rx4hvn/wbqoLe0y/35/
Hope this helps!