nested cards, fitting cards within a card - bootstrap cards

8.7k Views Asked by At

I am trying to do nested cards in my project, so basically I have three cards. The parent one Research Dashboard, the second one which holds the category ex. Recently Added Research and lastly, the third one or the third card which contains the image/card title and button. However, I am getting trouble when viewing it on a mobile browser. As you can see in the image the third card stretches up until the first card which is I do not like, the third card should only go to the second card which is Recently Added Research.

I've tried readjusting the width of the cards, but it gets destroy whenever I view it on the desktop browser which is I do not like.

enter image description here

<style>
        .card {
            /* Add shadows to create the "card" effect */
            box-shadow: 0 4px 8px 0 rgba(0, 0, 0, 0.2);
            transition: 0.3s;
            margin: 0 auto;
            float: none;
            margin-bottom: 10px;
        }

        /* On mouse-over, add a deeper shadow */
        .card:hover {
            box-shadow: 0 8px 16px 0 rgba(0, 0, 0, 0.2);
        }

        body {
            background-color: #003366;
        }
    </style>
</head>

<body>
    <div class="container-fluid" style="padding-top: 50px;">
        <div class="card">
            <div class="card-header text-center " style="font-family: Sans-Serif; text-transform:uppercase; font-size:1.5rem">
                Research Dashboard
            </div>
            <div class="card-body">
                <div class="container-fluid" style="padding-top: 50px;">
                    <div class="row">
                        <div class="col">
                            <div class="card  h-100">
                                <div class="card-header text-center " style="font-family: Sans-Serif; text-transform:uppercase; font-size:1.5rem">
                                    Recently Added Research
                                </div>
                                <div class="card-body">
                                    <div class="row">
                                        <div class="col">
                                            <div class="card" style="width: 18rem;">
                                                <img class="card-img-top" src="admin/files/Images/pagenotfound.png" alt="Card image cap">
                                                <div class="card-body">
                                                    <h5 class="card-title text-center">Card title</h5>
                                                    <button class="btn btn-info justify-content-start">View </button>
                                                    <button class="btn btn-info align-items-end">View </button>
                                                </div>
                                            </div>
                                        </div>
                                        <div class="col">
                                            <div class="card" style="width: 18rem;">
                                                <img class="card-img-top" src="admin/files/Images/pagenotfound.png" alt="Card image cap">
                                                <div class="card-body">
                                                    <h5 class="card-title text-center">Library Management System</h5>
                                                    <p class="card-text">Date added: <span>May 23, 2021</span></p>
                                                </div>
                                            </div>
                                        </div>
                                    </div>
                                </div>
                            </div>
                        </div>  
                    </div>
                </div>
            </div>
        </div>
    </div>

This is my ideal result. However, this image was a screenshot in desktop view.

enter image description here

1

There are 1 best solutions below

1
On BEST ANSWER

try this

.card {
            /* Add shadows to create the "card" effect */
            box-shadow: 0 4px 8px 0 rgba(0, 0, 0, 0.2);
            transition: 0.3s;
            margin: 0 auto;
            float: none;
            margin-bottom: 10px;
        }

        /* On mouse-over, add a deeper shadow */
        .card:hover {
            box-shadow: 0 8px 16px 0 rgba(0, 0, 0, 0.2);
        }

        body {
            background-color: #003366;
        }
<div class="container-fluid" style="padding-top: 50px;">
    <div class="card">
        <div class="card-header text-center " style="font-family: Sans-Serif; text-transform:uppercase; font-size:1.5rem">
            Research Dashboard
        </div>
        <div class="card-body">
            <div class="container-fluid" style="padding-top: 50px;">
                <div class="row">
                    <div class="col">
                        <div class="card  h-100">
                            <div class="card-header text-center " style="font-family: Sans-Serif; text-transform:uppercase; font-size:1.5rem">
                                Recently Added Research
                            </div>
                            <div class="card-body">
                                <div class="row">
                                    <div class="col">
                                        <div class="card" style="max-width: 18rem;">
                                            <img class="card-img-top" src="admin/files/Images/pagenotfound.png" alt="Card image cap">
                                            <div class="card-body">
                                                <h5 class="card-title text-center">Card title</h5>
                                                <button class="btn btn-info justify-content-start">View </button>
                                                <button class="btn btn-info align-items-end">View </button>
                                            </div>
                                        </div>
                                    </div>
                                    <div class="col">
                                        <div class="card" style="max-width: 18rem;">
                                            <img class="card-img-top" src="admin/files/Images/pagenotfound.png" alt="Card image cap">
                                            <div class="card-body">
                                                <h5 class="card-title text-center">Library Management System</h5>
                                                <p class="card-text">Date added: <span>May 23, 2021</span></p>
                                            </div>
                                        </div>
                                    </div>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>