Click here to Skip to main content
15,881,882 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hi Team

I Want to reduce size of my div card, they dont appear good. want them display 4 by 4 each row. How do i achieve this using bootstrap div card?

What I have tried:

// Display the products
$stmt = $pdo->query("SELECT * FROM products");
$products = $stmt->fetchAll(PDO::FETCH_ASSOC);

foreach ($products as $product) {
    $productID = $product['id'];
    $productName = $product['product_name'];
    $productPrice = $product['product_price'];
    $productImage = $product['product_image'];

    // Start a Bootstrap card
    echo "<div class='card product-card' >
            <img src='$productImage' class='card-img-top' alt='$productName'>
            <div class='card-body'>
                <h5 class='card-title'>$productName</h5>
                <p class='card-text'>Price: $productPrice</p>";
Posted
Updated 12-Jun-23 5:03am
Comments
Richard MacCutchan 12-Jun-23 10:53am    
THis looks like another question that is missing code and detail. Please review your entry before you post it.

You haven't told us which version of Bootstrap. But whichever version you're using, the answer is almost certainly in the documentation.

Bootstrap 5:
Grid system · Bootstrap v5.3[^]

Bootstrap 4:
Grid system · Bootstrap v4.6[^]

If you still can't get it working, then you need to explain precisely what you are trying to achieve, what you have tried, and where you are stuck. Include a minimal reproduction of the problem using JSFiddle[^], CodePen[^], or similar.
 
Share this answer
 
You can utilize the grid system and create a container with rows and columns in bootstrap -

Your html is incorrect by using php variables not contained within php tags.Your html will look like this -
<div class="container">
  <div class="row">
    <div class="col-md-3">
      <!-- Cart item 1 -->
      <div class="card product-card">
        <img src="<?php $productImage ?>" class="card-img-top" alt="<?php $productName ?>">
        <div class="card-body">
          <h5 class="card-title"><?php $productName ?></h5>
          <p class="card-text">Price: <?php $productPrice ?></p>
        </div>
      </div>
    </div>
    <div class="col-md-3">
      <!-- Cart item 2 -->
      <!-- Repeat the structure for the remaining cart items -->
    </div>
    <div class="col-md-3">
      <!-- Cart item 3 -->
      <!-- Repeat the structure for the remaining cart items -->
    </div>
    <div class="col-md-3">
      <!-- Cart item 4 -->
      <!-- Repeat the structure for the remaining cart items -->
    </div>
  </div>
  <div class="row">
    <!-- Next set of four cart items -->
    <!-- Repeat the structure for the next four cart items -->
  </div>
</div>


You can follow steps to create it at - CSS Grid Container[^]
 
Share this answer
 
v3

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900