Max-width, maximum element width in CSS
Width and max properties: width defines the width of the element.
Width and max properties: width defines the width of the element.
As mentioned earlier, the block element always takes up the full width (pull from the left to the right).Setting the width by the width property for the block element will prevent it from stretching to the outer edge.You can then set the margin automatically, centering the element horizontally.The element will only occupy the predefined width, the rest will be divided equally for the two margins.
Note: When the window width is smaller than the element, the browser adds a horizontal scroll bar to the page.In this case, max-width should be used.This just makes the browser easier to handle when the window is too small, which is also important on small screen devices.
Here is an example of how to use the above two width and max-width features.
div.ex1 {
width : 500px ;
margin : auto ;
border : 3px solid #73AD21 ;
}
div.ex2 {
max-width : 500px ;
margin : auto ;
border : 3px solid #73AD21 ;
}
Change the browser window width to see the difference
Previous lesson: Display element in CSS
The following article: Location of elements in CSS
- Laptop has maximum screen width
- Padding in CSS
- Outline in CSS
- Pseudo-Element in CSS
- How to adjust auto width on Excel
- Border in CSS
- Inspect Element: How to temporarily edit any website?
- Scientists discovered super heavy element 116, called livermorium
- CSS Selector in jQuery
- Steps to add/remove 'Maximum processor state' from Power Options in Windows
- Change the width of columns and the height of rows in Excel
- What factors determine the strength of a CPU?
- Corpse pose helps sleep well and regenerate energy
- How to adjust text spacing on PowerPoint - Keep the text width the same