Open In App

Explain function of the md-grid class in Bootstrap

Last Updated : 17 Dec, 2021
Improve
Improve
Like Article
Like
Save
Share
Report

Bootstrap’s Grid System: The bootstrap grid system is useful in designing the responsive application or website in which the column will rearrange depend upon the screen size. It allows up to 12 columns across the page. You can use each of them individually or merge them together for wider columns. All combinations of values summing up to 12 can be used. It gives the best experience to all devices. With the help of the bootstrap grid system, we can design and customize the width of the screen for small size screen width, medium size screen width, and large size screen width. Some of the classes provided by the Bootstrap grid system are the xs grid class for extra small, sm grid class for small, md grid class for medium, and lg grid class for large.

Grid Classes: Bootstrap grid system contains 5 classes which are listed below:

  • .col: It is used for extra small screen devices (screen width less than 576px).
  • .col-sm: It is used for small screen devices (screen width greater than or equal to 576px).
  • .col-md: It is used for medium screen size devices (screen width greater than or equal to 768px).
  • .col-lg: It is used for large screen size devices (screen width greater than or equal to 992px).
  • .col-xl: It is used for xlarge screen size devices (screen width equal to or greater than 1200px).

Components of Grid System:

  • Containers: Bootstrap requires a containing element to wrap site contents in a grid system. The word container is used to containing the row elements and row elements containing the column elements.
  • Rows: Rows must be placed within the container or container-fluid for proper alignment and padding. Rows are used to create horizontal groups of columns.
  • Columns: Grid columns are created by specifying the number of twelve available columns you wish to span. For example, three equal columns would use three col-lg-4.

.md-grid class: It is a class provided by Bootstrap’s grid system that will help to design the interface of websites or apps for a small-size device screen whose screen width is equal to 992px or near to 992px.

Syntax:

<div class="col-md-x">Content</div>
  • col: It is used for partitioning the row into columns.
  • md: This class is only applicable for devices with medium screen width.
  • x: There is a total of 12 grid columns and the container of class ‘col-md-x’ will have x grid columns.

Properties:

  • In order to use this class, we need to add “ .col-md- ” as a prefix in class.
  • This class is used for developing a responsive front-end for a small device screen whose width is equal to 992px or greater than 992px.
  • There is a maximum of 12 grid columns on the page but we can customize the screen by merging these columns.
  • The width of the container for this class can be 970px approx.

Example 1: In this example, the ‘col-mid-6 ‘ denotes 50% of the whole page width for medium size screen device because it will acquire 6 grid columns out of 12 grid columns.

HTML




<!DOCTYPE html>
<html lang="en">
 
<head>
 
    <!-- Bootstrap CSS -->
    <link rel="stylesheet" href=
 
    <!--Bootstrap Icons CSS -->
    <link rel="stylesheet" href=
</head>
 
<body>
    <!-- Row is class used for displaying
        partition of columns in a row  -->
    <div class="row">
 
        <!-- First partition of 50% width -->
        <div class="col-md-6"
            style="background-color: yellow">
            <h1>Welcome To ,</h1>
        </div>
 
        <!-- Second partition of 50% width -->
        <div class="col-md-6"
            style="background-color: greenyellow">
            <h1>GeeksforGeeks</h1>
        </div>
    </div>
</body>
 
</html>


Output:

output page showing 50%  width acquired with the help of ‘col-md-6″.

Example 2: In this example, the ” col-mid-3 ” denotes 25% of the whole page width because it will acquire 3 grid columns out of 12 grid columns. and ” col-mid-9 ” denotes 75% of the whole page width because it will acquire 9 grid columns out of 12 grid columns for medium size screen devices.

HTML




<!DOCTYPE html>
<html lang="en">
 
<head>
 
    <!-- Bootstrap CSS -->
    <link rel="stylesheet" href=
 
    <!--Bootstrap Icons CSS -->
    <link rel="stylesheet" href=
</head>
 
<body>
 
    <!-- Row is class used for displaying
        partition of columns in a row  -->
    <div class="row">
 
        <!-- First partition of 50% width -->
        <div class="col-md-3" style=
            "background-color: yellow">
            <h1>Welcome To,</h1>
        </div>
 
        <!-- Second partition of 50% width -->
        <div class="col-md-9" style=
            "background-color: greenyellow">
            <h1>GeeksforGeeks</h1>
        </div>
    </div>
</body>
 
</html>


Output:

output page showing 25% , 75%  width acquired with the help of ‘col-md-3″ , col-md-6 respectively.



Like Article
Suggest improvement
Share your thoughts in the comments

Similar Reads