Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Angular: Why doesn't CSS justification work with ng-repeat?

What I'm trying to do

I'm trying to evenly space the li in a ul (justify). The CSS works when I hardcode the li, but when I use ng-repeat, the CSS is no longer applied.

HTML

<div ng-app="SampleApp">
    <div ng-controller="ListCtrl">
        <ul class="two-column">
            <li></li>
            <li></li>
            <li></li>
            <li></li>
        </ul>

        <ul class="two-column">
            <li ng-repeat="item in items"></li>
        </ul>
    </div>
</div>

CSS

.two-column {
    text-align: justify;
}

.two-column:after {
    content: '';
    display: inline-block;
    width: 100%;   
}

The fiddle

http://jsfiddle.net/RyanWalters/M8228/

Expected result

Both lists should have space between each li.

Actual result

The list generated with ng-repeat has no space between each li.

Why is this happening?

like image 839
Ryan Avatar asked Apr 23 '14 18:04

Ryan


1 Answers

The whitespace between the li elements (necessary for the justification) is not emitted with Angular's repetition. You also have to wrap the whitespace so it gets repeated. You can do something like:

<span ng-repeat-start="item in items"></span>
    <li></li>
<span ng-repeat-end></span>

http://jsfiddle.net/M8228/1/

like image 77
Explosion Pills Avatar answered Oct 22 '22 02:10

Explosion Pills