3

I currently have an Angular application and my ng-repeat list is overflowing its container vertically. Here is a picture of the problem:

ng-repeat vertical overflow

As you can see the list is overflowing its container at the bottom. I would like the list to be contained in its container and a vertical scroll bar to show up when there is overflow.

I have tried using overflow:scroll and overflow:auto css on the div containing the list but nothing seems to work. The scrollbars do show up around the list but it doesn't limit the list to the height of its container. Here is my code, the code that makes the list is towards the bottom:

<div style="height: 90%">
    <h2>Foods and Meals</h2>
    <span class="glyphicon bg-fade"></span>
    <div class="jumbotron" id="foodJumbotron" style="height: 100%">
        <div class="container" style="height: 100%">
            <div class="row" style="height:100%">
                <div class="col-xs-6" style="height:100%">
                    <ul class="nav nav-tabs" role="tablist">
                        <li class="active"><a data-target="#foodsTab" role="tab" data-toggle="tab">Foods</a></li>
                        <li><a data-target="#myFoodsTab" role="tab" data-toggle="tab">My
                            Foods</a></li>
                        <li><a data-target="#myMealsTab" role="tab" data-toggle="tab">My
                            Meals</a></li>
                    </ul>
                    <div class="tab-content" style="height:100%">
                        <!------------->
                        <!--FOODS TAB-->
                        <!------------->
                        <div id="foodsTab" class="tab-pane fade active in" style="max-height:95%" ng-controller="FoodsCtrl">
                            <form role="from" class="form-inline row list-group-item">
                                <div style="width:100%">
                                    <span class="glyphicon glyphicon-search" style="margin-left: 0"></span>

                                    <input type="text" class="form-control " style="width:60%; margin-left: 2%"
                                           id="searchFoods"
                                           ng-model="search"
                                           placeholder="Search food database..."/>

                                    <div class="btn-group">
                                        <button type="submit" ladda="submitting" data-style="slide-right"
                                                id="foodsTabSearch"
                                                class="btn btn-primary btn-outline btn-sm btn-rounded">Search
                                        </button>
                                        <a class="btn btn-primary btn-outline btn-sm btn-rounded"
                                           ng-click="filter.changeState()">Filter</a>
                                    </div>
                                </div>
                            </form>
                            <div ng-show="filter.state" class="row" style="margin-top:4%;">
                                <div class="form-group ">
                                    <input type="text" class="form-control" id="filterFoods"
                                           ng-model="filter.value"
                                           placeholder="Filter results..."/>
                                </div>
                            </div>
                            <div class="list-group-item row gt-header-colors">
                                <div class="col-xs-4" ng-click="sort.doSort('name')" style="text-align: left">
                                    Name
                                    <span ng-show="sort.state.name == 'name'"
                                          class="glyphicon glyphicon-resize-small glyphicon-sort-by-alphabet"></span>
                                    <span ng-show="sort.state.name == '-name'"
                                          class="glyphicon glyphicon-sort-by-alphabet-alt"></span>
                                </div>
                                <div class="col-xs-2" ng-click="sort.doSort('cal')">Cal
                                    <span ng-show="sort.state.cal == 'cal'"
                                          class="glyphicon glyphicon-sort-by-attributes"></span>
                                    <span ng-show="sort.state.cal == '-cal'"
                                          class="glyphicon glyphicon-sort-by-attributes-alt"></span>
                                </div>
                                <div class="col-xs-2" ng-click="sort.doSort('pro')">Pro
                                    <span ng-show="sort.state.pro == 'pro'"
                                          class="glyphicon glyphicon-sort-by-attributes"></span>
                                    <span ng-show="sort.state.pro == '-pro'"
                                          class="glyphicon glyphicon-sort-by-attributes-alt"></span>
                                </div>

                                <div class="col-xs-2" ng-click="sort.doSort('carb')">Carb
                                    <span ng-show="sort.state.carb == 'carb'"
                                          class="glyphicon glyphicon-sort-by-attributes"></span>
                                    <span ng-show="sort.state.carb == '-carb'"
                                          class="glyphicon glyphicon-sort-by-attributes-alt"></span>
                                </div>
                                <div class="col-xs-2" ng-click="sort.doSort('fat')">Fat
                                    <span ng-show="sort.state.fat == 'fat'"
                                          class="glyphicon glyphicon-sort-by-attributes"></span>
                                    <span ng-show="sort.state.fat == '-fat'"
                                          class="glyphicon glyphicon-sort-by-attributes-alt"></span>
                                </div>
                            </div>
                            <!-------------------------------------->
                            <!--HERE'S THE LIST THAT'S OVERFLOWING-->
                            <!-------------------------------------->
                            <div class="" id="foodsList" ng-style="{'max-height':'60%'}">
                                <div class="gt-list-group-item gt-draggable"
                                     ng-repeat="food in filteredFoods = (FoodsService.foods | regexFilterNoCase:(filter.value == '' ?
                                        '' : '\\b'+filter.value) | orderBy: sort.state.current) track by $index"
                                     ng-style="{'background-color': food == FoodsService.selectedFood ? 'lightblue' : ''}"
                                     ng-mousedown="FoodsService.selectedFood = food">
                                    <div class="col-xs-4" style="text-align: left">{{food.name}}</div>
                                    <div class="col-xs-2">{{food.cal}}</div>
                                    <div class="col-xs-2">{{food.pro}}</div>
                                    <div class="col-xs-2">{{food.carb}}</div>
                                    <div class="col-xs-2">{{food.fat}}</div>
                                </div>
                                <div class="gt-list-group-item" ng-show="filteredFoods.length == 0"
                                     ng-style="{'text-align':'center'}">
                                    <div class="col-xs-12">No foods here!</div>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>

EDIT

Here are my custom css classes. They are actually in a less file but the only less attribute I use is extend. Everything else is basic css.

.gt-appfront-error:extend(.help-block all) {
  color: #ffff00;
  text-align: left;
  font-size: large
}

.gt-list-item {
  font-size: 150%;
}

.gt-header-colors {
  background-color: #3ca2e0;
  color: #FFF
}

/*Verticly align div*/
.gt-outer {
  display: table;
  //position: absolute;
  height: 100%;
  width: 100%;
}

.gt-middle {
  display: table-cell;
  vertical-align: middle;
}

.gt-inner {
  margin-left: auto;
  margin-right: auto;
}

.gt-list-group-item {
  &:extend(.row all);
  &:extend(.list-group-item all);
  border-color: darkgray;
}

.gt-list-group-item:hover {
  background-color: #d2e9f4;
}

.gt-draggable {
  cursor: pointer;
}

.gt-droppable {
  border-width: 5%;
  border-style: dashed;
  border-color: #ccc;
}

.gt-active-droppable {
  border-color: #3ca2e0;
}

/* Tab Navigation */
.nav-tabs {
  margin: 0;
  padding: 0;
  border: 0;
}

.nav-tabs > li > a {
  background: #DADADA;
  border-radius: 0;
  cursor: pointer;
  color: #555555;
  margin-bottom: 0px;
  box-shadow: inset 0 -8px 7px -9px rgba(0, 0, 0, .4);
}

.nav-tabs > li > a:hover {
  background-color: lightblue !important;
}

.nav-tabs > li.active > a,
.nav-tabs > li.active > a:hover {
  background: white !important;
  border-radius: 5%;
  border-width: 2px;
  box-shadow: inset 0 0 0 0 rgba(0, 0, 0, .4);
}

/* Tab Content */
.tab-pane {
  background: white;
  box-shadow: 0 0 4px rgba(0, 0, 0, .4);
  border-radius: 0% 2% 2% 2%;
  text-align: center;
  padding: 5% 6% 1% 6%;
  margin-top: 0px;
  margin-left: 2px;
}

//.animate-show.ng-hide-add {
//  animation: fadeOut 0.5s ease !important;
//}

.animate-show.ng-hide-remove {
  animation: fadeIn 0.3s ease !important;
}

Any help would be greatly appreciated.

||||||
  • Can you add css, or better jsfiddle? – Nora Jan 9 '16 at 20:10
  • does the "foodsList" div have a defined height in the css? if not then the overflow:scroll wont work – BinaryGhost Jan 9 '16 at 20:11
  • @Nora I'll include my main.css. It is a huge file but the css classes can still be found if you do a search in the file. My app is too large now to put it all in a jsFiddle though. – Graham Jan 9 '16 at 20:23
  • @BinaryGhost yes it has a set height and max-height. The scrollbars do show up. But it doesn't respect the height or max-height attributes at all when the items are generated by ng-repeat. – Graham Jan 9 '16 at 20:25
0

Graham. It is pretty had for us to give you an answer as long as we don't have your working project, but I think the changes you should make are as follows:

  • The "gt-list-group-item" divs should have another class, "row" (I believe you are using Bootstrap since you have col-xs-4 and so on.
  • Add Overflow:scroll to the foodList div.

Please come back with feedback if it does not work.

||||||
  • Thank you for the answer. I'm using less, and gt-list-group-item extends row. So gt-list-group-item is a row. I've also tried putting overflow:scroll on the foodList div and all that does is add a vertical and horizontal scroll bars but the height of the list stays the same, still ignoring the css height attributes set on its container. – Graham Jan 9 '16 at 21:44
  • prntscr.com/9o3rhh here's how it looks here after I did the aforementioned changes. Maybe your gt-list-group-item or gt-draggable overwrites some of .row's key properties. Can't hurt trying. (The group item div has been copied 2 times to get some content in there) – Paul Daniel Ghiran Jan 9 '16 at 21:52
  • I made the changes you mentioned and here it is: imgur.com/rQzGzs9 So it doesn't look like it has to do with that particular css. – Graham Jan 9 '16 at 22:17
  • foodTab has a max-height of 95%. Try loosing that. – Paul Daniel Ghiran Jan 9 '16 at 22:26
  • In your latest screenshot it seems to me that your foodList is getting out of the screen, not the items as I previously thought. so it either has to be made smaller to fit foodTab or foodTab has to be changed. It seems to me your foodsList's max height does not work. I suggest using a fixed max-height (in pixels) on your foodList and removing the max-height on foodsTab – Paul Daniel Ghiran Jan 9 '16 at 22:40
0

The problem was that the div containing the ng-repeat list, in this case the div with id="foodsTab", did not have its height explicitly set. It only had the max-height set. The ng-repeat list needed this height value to determine its own height.

||||||

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.