01 / 05
Fit any screen width
INPUT · Slides
Put a cap on so it cannot spread too far
02 / 05
max-width is a "this far" line
max-width sets an upper limit. It will not go beyond the value you wrote, and on a screen narrower than that it shrinks properly.
Writing it as a pair with width: 100%; is the standard shape.
.container { width: 100%; max-width: 640px;}03 / 05
How it differs from width
width: 640px; is fixed. On a 400px screen it spills out and you get a sideways scrollbar.
With max-width: 640px;:
- wide screen … it stops at 640px
- narrow screen … it shrinks to fit
This setting ties one side only.
04 / 05
It stops pictures spilling out too
A picture shows at its own size, so a picture bigger than its parent spills out. Write max-width: 100%; and you have the limit "never bigger than the parent".
It may be the single most used line in coping with width.
.frame img { max-width: 100%;}05 / 05
Let the contents decide the cap
About 600 to 700px for text, wider where you are showing photographs. The cap is whatever width suits what is inside.
Have a go.