Created
August 1, 2024 04:09
-
-
Save bowber/f10e15c7c6ca53e80cdf8937d6d3b5bf to your computer and use it in GitHub Desktop.
Auto scale font size for quick & dirty responsive
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <!DOCTYPE html> | |
| <html lang="en"> | |
| <head> | |
| <meta charset="UTF-8" /> | |
| <link rel="icon" type="image/png" href="/images/logo.png" /> | |
| <meta name="viewport" content="width=device-width, initial-scale=1.0" /> | |
| <title>Document</title> | |
| </head> | |
| <body> | |
| <div id="root"></div> | |
| <script> | |
| // Auto set font size for mobile to scale easier | |
| if (window.innerWidth < 513) { | |
| document.documentElement.style.fontSize = | |
| (window.innerWidth / 513) * 16 + 'px' | |
| // Base on 513px width to set 16px font size | |
| // Because 513px width is designer's design width | |
| } | |
| // Use rem unit for every element to scale easier | |
| </script> | |
| <script type="module" src="/src/index.tsx"></script> | |
| </body> | |
| </html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment