tiberhockey
tiberhockey

Reputation: 576

Bootstrap grid not aligned properly

With the django framework I use a loop in my templates to display the image inside my database, I also use the Bootstrap grid to make it clean, but it not working correctly. As you can see the image on at the bottom are not align correctly.

enter image description here

hmtl

<div class="container">
    <div class="row">
        <div class="col-sm-12 col-md-3 col-lg-2">
            <div class="card-filter" style="width: 10rem;">
                <div class="card-header">
                    Pattern Type
                </div>
                <ul class="list-group list-group-flush">
                    {% for pattern in categories %}
                    <li class="list-group-item">{{pattern.name}}</li>
                    {% endfor %}
                </ul>
            </div>
        </div>
        {% for photo in photos %}
        <div class="col-sm-12 col-md-5 col-ld-5">
            <div class="card" style="width: 25rem;">
                <img class="card-img-top" src="{{photo.image.url}}" alt="Card image cap">
                <div class="card-body">
                    <p class="card-text">Symbol: GBPUSD<br>Pattern: ButterFly Bullish</p>
                    <a href="{% url 'photo' photo.id %}" class="btn btn-dark">View Pattern</a>
                </div>
            </div>
        </div>
        {% endfor %}
    </div>
</div>

views.py

def home(request):
    categories = Category.objects.all()
    photos = Photo.objects.all()

    context = {'categories': categories,
               'photos': photos}

    return render(request, "main/home.html", context)

Upvotes: 2

Views: 65

Answers (1)

Mohammed Ahmed
Mohammed Ahmed

Reputation: 435

You better put all the images in a parent that takes rest of the width after the list on the left, so it should be like this:

<div class="container">
  <div class="row">
    <div class="col-sm-12 col-md-3 col-lg-2">
      <div class="card-filter" style="width: 10rem;">
        <div class="card-header">
          Pattern Type
        </div>
        <ul class="list-group list-group-flush">
          {% for pattern in categories %}
          <li class="list-group-item">{{pattern.name}}</li>
          {% endfor %}
        </ul>
      </div>
    </div>
    <div class="col-sm-12 col-md-9 col-lg-10">
        {% for photo in photos %}
        <div class="col-sm-12 col-md-6">
          <div class="card" style="width: 25rem;">
            <img
              class="card-img-top"
              src="{{photo.image.url}}"
              alt="Card image cap"
            />
            <div class="card-body">
              <p class="card-text">
                Symbol: GBPUSD<br />Pattern: ButterFly Bullish
              </p>
              <a href="{% url 'photo' photo.id %}" class="btn btn-dark"
                >View Pattern</a
              >
            </div>
          </div>
        </div>
        {% endfor %}
    </div>
  </div>
</div>

Upvotes: 1

Related Questions