My CSS stylesheet supports a ‘desktop’ and ‘mobile’ layout depending on screen width (media queries).
I ensure that the mobile layout is used by default so that if media queries aren’t supported that the mobile layout is used.
(I also use IE 8 specific code to support that, but please ignore that for this post)
I then style a div something like this (two class names below)
<div class=“half-width-box show-full-width-on-mobile”>
So:
<style>
.half-width-box {
width: 50%;
}
@media all and (max-width: 469px) {
.show-full-width-on-mobile {
width: 100%;
}
}
</style>
So now it automatically shows full width on a screen smaller than 470px.
The problem is that if media queries aren;t supported (e.g. old mobile device) then it won’t work properly unless I do this:
<style>
.half-width-box {
width: 50%;
}
.show-full-width-on-mobile {
width: 100%;
}
@media all and (min-width: 470px) {
.show-full-width-on-mobile {
*** completely ignore this style element as though it wasn’t used ***
}
}
</style>
The above would be great as if media queries weren’t supported then it would work, but only if .show-full-width-on-mobile can be ignored at 470px and above.
I can’t set a width value on .show-full-width-on-mobile (for 470px and above) as I don’t know what the other class value would be, as it could be something like this:
<div class=“quarter-width-box show-full-width-on-mobile”>
(and of course loads of other styling is needed other than just width on all the class names)
Hope this makes sense. I really can’t completely change everything as the above is just an example of the entire thing.
Thanks.