Setting the width
of a block-level element will prevent it from stretching out to the edges of its container (good for things like readable line lengths).
Therefore, the wrapper element will take up the specified width.
The problem occurs when the browser window is narrower than the specific width of the wrapper.
That will trigger a horizontal scrollbar, which is almost always undesirable.
Using max-width
instead, in this situation, is better for narrower browser windows.
This is important when making a site usable on small devices.
Here's a good example showcasing the problem.
<div class="width">This div element has width: 960px;</div>
<br />
<div class="max-width">This div element has max-width: 960px;</div>
<br />
<strong>Note:</strong> Drag the browser window to smaller than 960px wide, to see the difference between the two divs!
/**
* The problem with this one occurs
* when the browser window is smaller than 960px.
* The browser then adds a horizontal scrollbar to the page.
*/
.width {
width: 960px;
margin-left: auto;
margin-right: auto;
border: 3px solid #73AD21;
}
/**
* Using max-width instead, in this situation,
* will improve the browser's handling of small windows.
* This is important when making a site usable on small devices.
*/
.max-width {
max-width: 960px;
margin-left: auto;
margin-right: auto;
border: 3px solid #73AD21;
}
/**
* Credits for the tip: W3Schools
* https://www.w3schools.com/css/css_max-width.asp
*/
In terms of responsiveness, max-width is the better choice!