Home > Article > Web Front-end > How do 'col-md-4', 'col-xs-1', and 'col-lg-2' work in the Bootstrap Grid System?
Grid System in Bootstrap: Understanding "col-md-4", "col-xs-1", and "col-lg-2"
The Bootstrap grid system enables you to control the layout and alignment of elements in various screen sizes. The "col-" classes, coupled with numbers, play a crucial role in this system.
How the Numbers Align Grids
The numbers in the "col-*" classes represent the width of a column relative to a container's total width. Each container can accommodate 12 columns in total. Therefore, "col-md-6" would take up 6 columns out of 12, resulting in a column that is half the container's width.
Using the Numbers
To use these numbers, simply include the appropriate "col-" class followed by the number. For example, a div with the class "col-xs-3" would occupy 3 columns on extra small screens (i.e., mobile phones), while a div with the class "col-sm-6" would take up 6 columns on small screens (i.e., tablets).
What They Represent
The numbers in "col-*" represent the responsive breakpoints defined in Bootstrap. The letters xs, sm, md, and lg correspond to:
By using multiple "col-" classes on an element, you can specify how it should behave at different screen sizes. For instance, the following code would create a column that takes up half the width on mobile phones but only one-third of the width on tablets:
<div>
Understanding the "col-*" classes allows you to create flexible and responsive layouts in Bootstrap. By controlling the number and size of columns, you can achieve an optimal user experience across various devices.
The above is the detailed content of How do 'col-md-4', 'col-xs-1', and 'col-lg-2' work in the Bootstrap Grid System?. For more information, please follow other related articles on the PHP Chinese website!