Approach # 2 works better for me.
When I was a beginner, I used Approach No. 1 . I wrote my media queries together (at the bottom of my stylesheet or in another file).
.header { ... } .news-item { ... } .footer { ... } @media screen and (max-width: 1024px) { .header { ... } .news-item { ... } }
This approach has several disadvantages. Based on my experience, the most remarkable is that maintainability is tough . Main reason: .news-item
logic extends to several unrelated CSS lines.
Later, naturally, I decided to keep the related styles together. Approach # 2 :
.header { ... } @media screen and (max-width: 1024px) { .header { ... } } @media screen and (max-width: 720px) { .header { ... } } .news-item { ... } @media screen and (max-width: 1024px) { .news-item { ... } } @media screen and (max-width: 720px) { .news-item { ... } }
However, in this approach, repeated requests for media max-width
all-around values ββdo not look acceptable. I solved this problem using a CSS preprocessor (like SASS), which allows me to replace all of them with variables and define them once.
To improve serviceability and make these definitions more elegant, I started using abstraction on top of media queries.
If you are interested in more detailed information, read in your blog post :-)
source share