diff --git a/src/App.css b/src/App.css index 47e1678..d647ae7 100644 --- a/src/App.css +++ b/src/App.css @@ -35,7 +35,10 @@ align-items: center; flex: 1; width: 100%; + max-width: 100vw; + overflow: hidden; box-sizing: border-box; + padding: 0 20px; } /* Digital clock style (default) */ @@ -46,6 +49,8 @@ text-shadow: 0 0 20px rgba(255, 255, 255, 0.5); letter-spacing: 0.05em; white-space: nowrap; + max-width: 100%; + overflow: hidden; } .style-button { diff --git a/src/App.tsx b/src/App.tsx index 85e5d6f..32dd69e 100644 --- a/src/App.tsx +++ b/src/App.tsx @@ -6,18 +6,14 @@ import './App.css' type ClockStyle = 'digital' | 'flip' | 'roll' function DigitalClock({ time, size }: { time: string; size: number }) { - // Match width with flip/roll clocks - // Total flip/roll width ≈ 5.1 * (size / 1.6) because size is now scaled - // Actually size passed in is already the final size - // Flip: 6 * (size * 0.75) + 2 * (size * 0.3) = 4.5 * size + 0.6 * size = 5.1 * size - // Digital: 8 chars, each char ≈ fontSize * 0.6 wide in monospace = 4.8 * fontSize - // To match: 4.8 * fontSize = 5.1 * size => fontSize = size * 1.06 - const fontSize = Math.floor(size * 1.06) + // Match visual height with flip/roll clocks + // Use slightly smaller than size to prevent overflow, but keep height similar + const fontSize = Math.floor(size * 0.95) return (
{time}
@@ -36,14 +32,17 @@ function App() { return () => clearInterval(timer) }, []) - // Responsive clock size - target 90% of page width + // Responsive clock size - fit within screen width useEffect(() => { const updateSize = () => { const width = window.innerWidth - // Direct calculation: target 90% width - const baseSize = (width * 0.9) / 5.1 - const newSize = Math.floor(baseSize * 2.0) // Scale up more - setClockSize(Math.min(newSize, 320)) + // More conservative for small screens + const margin = width < 480 ? 40 : 60 + const availableWidth = width - margin + // Use larger divisor for small screens to prevent overflow + const divisor = width < 480 ? 7 : 6 + const newSize = Math.floor(availableWidth / divisor) + setClockSize(Math.min(newSize, 200)) } updateSize() window.addEventListener('resize', updateSize)