html - 为什么 HTML Div 标签之间的边距随机

标签 html css angularjs

我正在尝试使用 angularJS 循环在 div 标签中填充数据。

<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>

这是我的 CSS 类。

.box {
margin : 5px;
display : inline-block;
width: 150px;
height: 250px;
background-color: grey;
text-align:center;
}

但它没有正确渲染。 (一些随机边距顶部和底部)

enter image description here

有人可以帮助我做错什么吗??

最佳答案

  1. 这是由于 vertical-align: middle 始终添加 vertical-align: top;display: inline-block;

  2. 第二个问题是边距未知,display: inline-block; 元素获取边距,将font-size: 0 添加到其父级。 :)

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>

关于html - 为什么 HTML Div 标签之间的边距随机,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29396604/

相关文章:

http - Angular JS 在调用新的 $http 之前取消 $http 调用

javascript - 清空 $_POST。值最终以 $GLOBAL 结尾

html - CSS 将图像裁剪到特定尺寸

javascript - 用 a4 尺寸缩放 div 和表格

css - 使用 Typescript 在我的 SASS 代码中注入(inject)背景 url ("MyImageHere.png"

html - 处理 IMAP HTML 电子邮件时,如何隔离内联 CSS?

javascript - 我应该如何在不使用范围的情况下在我的 Controller 功能中引用服务?

html - 字体文件(例如 .ttc .ttf .otf)是否包含不同的权重?

php - javascript if 语句出现问题

javascript - 使用固定的顶部栏滚动到 id