With CSS You can simply base on screen-width
and media-queries
(https://developer.mozilla.org/en-US/docs/Web/Guide/CSS/Media_queries). Take a look how, for example Twitter Bootstrap is developed.
And with JS there is a lot to say about this, but most You can find for example in this topic: How to detect a mobile device with JavaScript?
I ussualy try to keep this information in my JS App namespace with COnfigs, for example (with Twig)
var App = {
'CONFIG' : {
'IS_TABLET' : {% if isTablet() %}true{% else %}false{% endif %},
'IS_PHONE' : {% if isMobile() %}true{% else %}false{% endif %}
}
}
Where isTablet()
and isMobile()
are from backend where is possible to detect it with some useful Bundles (in Symfony2 case).
But the best what You can do it is making one solution which will be work across different devices / browsers / display sizes etc. Rather than hack your solutions, try to make it universal