Open In App

Bootstrap 5 Cards Sizing

Last Updated : 09 May, 2024
Comments
Improve
Suggest changes
Like Article
Like
Report

Bootstrap Cards Sizing refers to the ability to control the dimensions of cards in Bootstrap by using predefined classes such as col, col-sm, col-md, col-lg, col-xl, and col-xxl. This ensures consistency and responsiveness across various screen sizes, maintaining a uniform appearance for card elements.

Bootstrap 5 Cards Sizing can set the width of the card using custom CSS, grid classes, grid Sass mixins, or utilities.

ClassDescription
colSets the column width equally for all screen sizes.
col-smAdjust the column width for small-sized screens.
col-mdAdjusts the column width for medium-sized screens.
col-lgAdjusts the column width for large-sized screens.
col-xlAdjusts the column width for extra-large screens.
col-xxlAdjusts the column width for extra-large screens.

Examples of Bootstrap Cards Sizing

Example 1: In this example, we will learn about Cards using custom CSS, and set the size of cards using inline CSS

HTML
<!DOCTYPE html>
<html>

<head>
    <!-- Load Bootstrap -->
    <link href=
"https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" 
         rel="stylesheet"
        integrity=
"sha384-EVSTQN3/azprG1Anm3QDgpJLIm9Nao0Yz1ztcQTwFspd3yD65VohhpuuCOmLASjC" 
         crossorigin="anonymous">
</head>

<body class="p-3">
    <div class="container">
        <div class="w-50">
            <h3 class="mb-4">Cards Using Bootstrap 5 Sizing</h3>

            <div class="card" style="max-width: 350px;">
                <img src=
"https://media.geeksforgeeks.org/wp-content/cdn-uploads/Java.png" 
                     class="card-img-top">
                <div class="card-body">
                    <h5 class="card-title">Java</h5>
                    <p class="card-text">
                        Java is Object Oriented. However, it is not 
                        considered as pure object-oriented
                        as it provides support for primitive 
                        data types (like int, char, etc)
                    </p>
                </div>
            </div>
        </div>
    </div>
</body>

</html>

Output

Bootstrap-5-Card-Sizing
Bootstrap 5 Cards Sizing Example

Example 2: Bootstrap 5 Cards Sizing example utilizes "w-75" class to set card width to 75% of the parent container, displaying an image and text content for Java programming language.

HTML
<!DOCTYPE html>
<html>

<head>
    <!-- Load Bootstrap -->
    <link href=
"https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" 
        rel="stylesheet"
        integrity=
"sha384-EVSTQN3/azprG1Anm3QDgpJLIm9Nao0Yz1ztcQTwFspd3yD65VohhpuuCOmLASjC" 
        crossorigin="anonymous">
</head>

<body class="m-4">
    <div>
        <h3>Cards Using Bootstrap 5 Sizing</h3>

        <div class="card w-75">
            <img src=
"https://media.geeksforgeeks.org/wp-content/cdn-uploads/Java.png" 
                 class="card-img-top">
            <div class="card-body">
                <h5 class="card-title">Java</h5>
                <p class="card-text">
                    Java is Object Oriented. However, 
                    it is not considered as pure object-oriented
                    as it provides support for primitive 
                    data types (like int, char, etc)
                </p>
            </div>
        </div>
    </div>
</body>

</html>

Output:

Bootstrap-5-Cards-Sizing-Example-2
Bootstrap 5 Cards Sizing Example Output



Similar Reads