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: 1
I am using these mixins & variables
.max(@max; @rules){@media only screen and (max-width: (@max - 1)){@rules();}}
.min(@min; @rules){@media only screen and (min-width: @min){@rules();}}
.bw(@min; @max; @rules){@media only screen and (min-width: @min) and (max-width: (@max - 1)){@rules();}}
@pad: 480px;
@tab: 800px;
@desktop: 992px;
@hd: 1200px;
So this
footer{
width: 100%;
.bw(@tab,@desktop,{
width: 768px;
});
.min(@desktop,{
width: 940px;
});
}
becomes
footer {
width: 100%;
}
@media only screen and (min-width: 800px) and (max-width: 991px) {
footer {
width: 768px;
}
}
@media only screen and (min-width: 992px) {
footer {
width: 940px;
}
}
I completely agree with Hai Nguyen's answer (which has been accepted) but you can clean it up a bit more by doing something like this:
@desktop: ~"only screen and (min-width: 960px) and (max-width: 1199px)";
@tablet: ~"only screen and (min-width: 720px) and (max-width: 959px)";
footer{
width: 100%;
@media @tablet {
width: 768px;
}
@media @desktop {
width: 940px;
}
}
It's essentially the same thing but lets you nest your media queries inside of the original selector. It keeps all css for a specific element together and makes your styles much more modular (vs the split breakpoint approach).