Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Angular ngFor with 2 columns and rows aligning

Tags:

angular

I have an Angular5 app and have an array of strings that I want to display in 2 columns. I have the following code:

<div *ngFor="let singleItem of sevices;">
    <div style="width: 45%; float: left;background-color:red">
        {{singleItem}}            
    </div>        
</div>

This works, however if the string is too long, it can cause what looks like an empty column in the left side of a row. I want to be able to have a left and right column appear in one row, and have the tops of each column align. Any ideas how to do this?

like image 855
CaptainMorgan Avatar asked Mar 07 '23 11:03

CaptainMorgan


2 Answers

Simplest solution was to add the CSS class "column-count:2;" to my outer div.

like image 193
CaptainMorgan Avatar answered Mar 15 '23 20:03

CaptainMorgan


You can use bootstrap classes if you have included it into your app.

<div class="row" *ngFor="let singleItem of sevices;let i = index;">
    <div class="col-md-6 left-style" *ngIf="i%2 == 0">
        {{singleItem}}            
    </div>  
    <div class="col-md-6 right-style" *ngIf="i%2 != 0">
        {{singleItem}}            
    </div>  
</div>

You can now add your styles to given class to col-md-6 divs

like image 39
Kishan Avatar answered Mar 15 '23 20:03

Kishan