Dr. Mark Humphrys

School of Computing. Dublin City University.

Online coding site: Ancient Brain

coders   JavaScript worlds

Search:

Free AI exercises


Cross-platform web design

Cross-browser, and cross-platform


  


Detect what the browser supports




Mobile web design


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:

  1. <meta name=viewport in head
  2. Flexbox ("display: flex;") for any wide content sections - put them into divs in a row and let them wrap
  3. "overflow-x: auto;" horizontal scrollbar for content that cannot wrap (table, pre)
  4. CSS gives all img a max-width: by default
  5. element widths use "vw" rather than absolute dimensions or "%"

  6. Checklist of wide things:
    • wide images
    • wide tables
    • wide iframes (like YouTube)
    • wide <pre> sections


Other solutions

There are many other approaches.

Probably don't:


Examples (my sites):

  


Different content on mobile

  


JS detect mobile

How can JS on the client detect mobile or desktop?
  

window.orientation



ancientbrain.com      w2mind.org      humphrysfamilytree.com

On the Internet since 1987.      New 250 G VPS server.

Note: Links on this site to user-generated content like Wikipedia are highlighted in red as possibly unreliable. My view is that such links are highly useful but flawed.