htmlcssangularjstwitter-bootstrapbootstrap-4

Bootstrap positioning objects dynamically in columns


I'm trying to display some objects in 3 columns using Bootstrap 4. When using this code it only appears in 1 column, like this: web 1 column.

But my idea is to be displayed like this (more or less): web template 3 columns.

<div class="row-mt-5">
          <div ng-repeat="woman in women">
            <div class= "col-lg-4">
                <!--Card-->
                  <div class="card">
                      <!--Card image-->
                      <img class="img-fluid" ng-src="{{woman.image_url}}" alt="{{woman.name}}">
                      <!--Card content-->
                      <div class="card-body">
                          <!--Title-->
                          <h4 class="card-title">{{woman.name}}</h4>
                          <!--Text-->
                          <p class="card-text"> <h5>{{woman.field}}</h5> <br> {{woman.job}}</p>
                          <a href="#!/women/details/{{woman._id}}" class="btn btn-primary">Learn more</a>
                      </div>
                  </div>
                  <!--/.Card-->
            </div>
          </div>
        </div>

I want to learn to use Bootstrap classes for object positioning.


Solution

  • First you need to know about the basic layout structure, learn it here, Please note that you need to define the grid layout for all the screens (sm md lg xl) the details are found in the link provided. Please refer to the below fiddle the code fix for your issue. I have included the ng-app and ng-controller for testing purposes, please ignore that.

    HTML:

    <div class="container-fluid" ng-app="myApp" ng-controller="MyController">
      <div class="row">
        <div class= "col-4 col-sm-4 col-md-4 col-lg-4" ng-repeat="woman in women">
          <!--Card-->
          <div class="card">
            <!--Card image-->
            <img class="img-fluid" ng-src="{{woman.image_url}}" alt="{{woman.name}}">
            <!--Card content-->
            <div class="card-body">
              <!--Title-->
              <h4 class="card-title">{{woman.name}}</h4>
              <!--Text-->
              <p class="card-text"> 
                <h5>{{woman.field}}{{woman.job}}</h5>
              </p>
            <a href="#!/women/details/{{woman._id}}" class="btn btn-primary">Learn more</a>
          </div>
        </div>
        <!--/.Card-->
      </div>
    </div>
    

    JSFiddle: here