Skip to content

Instantly share code, notes, and snippets.

@bowber
Created August 1, 2024 04:09
Show Gist options
  • Select an option

  • Save bowber/f10e15c7c6ca53e80cdf8937d6d3b5bf to your computer and use it in GitHub Desktop.

Select an option

Save bowber/f10e15c7c6ca53e80cdf8937d6d3b5bf to your computer and use it in GitHub Desktop.
Auto scale font size for quick & dirty responsive
<!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