It would be nice to wrap css-styles for different resolutions within some css-classes using less.
I'd like to do something like:
footer { width: 100%; } .tablet { footer { width: 768px; } } .desktop { footer { width: 940px; } }
At the end something like this should be the result:
footer { width: 100%; } @media screen and (min-width: 768px) { footer { width: 768px; } } @media screen and (min-width: 992px) { footer { width: 940px; } }
.tablet could look somehow like this:
@media screen and (min-width: 768px) { .tablet { } }
Hope somebody has a nice idea!
As you can see, you can have multiple conditions for the same media query. In order to test this, you need to resize your window so that it has a lower width. This can be done by pressing F12 in your browser. If you are using Chrome, a new area should appear, either on the side, bottom, or as a separate window.
And even though media queries are still a valid tool to create responsive interfaces, there are many situations where it's possible to avoid using width at all. Modern CSS allow us to create flexible layouts with CSS grid and flex that adapts our content to the viewport size without a need to add breakpoints.
Media queries are a key part of responsive web design, as they allow you to create different layouts depending on the size of the viewport, but they can also be used to detect other things about the environment your site is running on, for example whether the user is using a touchscreen rather than a mouse.
Here is what I've done in my projects:
@desktop: ~"only screen and (min-width: 960px) and (max-width: 1199px)"; @tablet: ~"only screen and (min-width: 720px) and (max-width: 959px)"; @media @desktop { footer { width: 940px; } } @media @tablet { footer { width: 768px; } }
This allows you to only define your media queries once and you can use it throughout your less files. Also a little easier to read. :)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With