I want to show products as a table but they show up in a vertical line

Issue

I have copied the bootstrap card code from the offical site and tried many changes to my code but the output always comes in a vertical line.

How to make these product cards appear as table with 3 columns?

{% extends 'base.html' %}
{% block content %}
<h1>Products</h1>
<div class="row">
  {% for product in products %}
  <div class="col-sm-4">
    <div class="card" style="width: 18rem;">
      <img src="{{ product.image_url }}" class="card-img-top" alt="..." width="300" height="300">
      <div class="card-body">
        <h5 class="card-title">{{ product.name }}</h5>
        <p class="card-text">${{ product.price }}</p>
        <a href="#" class="btn btn-primary">Add to Cart</a>
      </div>
    </div>
  </div>
  {% endfor %}
</div>
{% endblock %}

This is the output I am getting

Solution

If you missed adding the CSS and JS files of bootstrap 4 in your base.html, add the below file to your code.

<!-- bootstrap.min.css -->
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap@4.6.2/dist/css/bootstrap.min.css">

<!-- jquery and bootstrap.bundle.min.js -->
<script src="https://cdn.jsdelivr.net/npm/jquery@3.5.1/dist/jquery.slim.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/bootstrap@4.6.2/dist/js/bootstrap.bundle.min.js"></script>

Answered By – Ponsiva

Answer Checked By – Pedro (AngularFixing Volunteer)

Leave a Reply

Your email address will not be published.