Reputation: 9212
I am trying to fill the data in div tag using angularJS loop.
<div>
<div class='box' ng-repeat="product in Products | filter:{'scid': SCId.toString()}:true | orderBy:'pname'">
<br>
<b>{{product.bname}} </b>
<br>{{ product.pname }}
<br>
<img src="http://localhost/{{ product.image_path }}" alt="" border=3 height=75 width=75></img>
</div>
</div>
This is my CSS Class.
.box {
margin : 5px;
display : inline-block;
width: 150px;
height: 250px;
background-color: grey;
text-align:center;
}
But its not rendering properly. (some random margin top and bottom)
Can someone help what i am doing wrong??
Upvotes: 1
Views: 1693
Reputation: 60553
this is because display:inline-block
, is by default set to vertical-align:baseline
, so you need to set vertical-align:top
.
An element set to
inline-block
is very similar toinline
in that it will setinline
with the natural flow of text (on the "baseline
"). The difference is that you are able to set awidth
andheight
which will be respected.
Plus display:inline-block
causes gap between elements, which there are a few solutions to fix them:
so here is a snippet:
.box-wrapper {
font-size: 0
}
.box {
margin: 5px;
display: inline-block;
width: 150px;
height: 250px;
background-color: grey;
text-align: center;
vertical-align: top;
font-size: 16px;
}
<div class="box-wrapper">
<div class="box">this will be vertical aligned top</div>
<div class="box">this will be vertical aligned top</div>
<div class="box">this will be vertical aligned top</div>
</div>
Upvotes: 1
Reputation: 2102
This is due to vertical-align: middle
always add vertical-align: top;
with display: inline-block;
Second problem is unknown margins, display: inline-block;
elements get margin, add font-size: 0
to its parent. :)
ul {
max-width: 500px;
font-size: 0;
margin: 0 auto;
}
ul > li {
display: inline-block;
width: 100px;
height: 150px;
background: black;
margin: 5px;
list-style: none;
vertical-align: top;
}
<ul>
<li></li>
<li></li>
<li></li>
<li></li>
<li></li>
<li></li>
</ul>
Upvotes: 4