Cross-platform web design
Cross-browser, and cross-platform
Detect what the browser supports
Solution with HTML and CSS
You can have the same site for both mobile and desktop
using HTML and CSS alone (no JS).
Use the following:
- <meta name=viewport
in head
- Flexbox ("display: flex;")
for any wide content sections - put them into divs in a row and let them wrap
- "overflow-x: auto;" horizontal scrollbar
for content that cannot wrap (table, pre)
- CSS gives all img a max-width: by default
- element widths use "vw"
rather than absolute dimensions or "%"
- Checklist of wide things:
- wide images
- wide tables
- wide iframes (like YouTube)
- wide <pre> sections
Other solutions
There are many other approaches.
-
@media
(CSS media query)
can define CSS different for different devices.
- <link media=
can load entire different CSS file depending on device.
- separate mobile.css
- separate mobile pages
Probably don't:
- Server detect client using HTTP_USER_AGENT
- JS on client-side detect client
Examples (my sites):
Different content on mobile
- If you want to provide less or different actual content to the mobile site.
- Could ask user to click on "mobile site" but maybe that is awkward.
- Can provide all content to page, in hidden div's,
and then client side CSS or JS unhides some div's.
- Any other ways of doing it?
JS detect mobile
How can JS on the client detect mobile or desktop?
window.orientation