html - float div 未正确换行

标签 html css css-float

我有一堆 div 设置为 float 。出于某种原因,当它达到 3 行 float div 时,div 开始表现得很滑稽。这是 JS fiddle :http://jsfiddle.net/grem28/nq1q55bz

好像和我设置的名字有关系。这是代码:

<div class="pdfs">
  <a href="#" target="_blank"><img src="#" /><br />AccuDrop</a>
</div>

<div class="pdfs">
  <a href="#" target="_blank"><img src="#" /><br />AccuPen Vet</a>
</div>

<div class="pdfs">
  <a href="#" target="_blank"><img src="#" /><br />Accutome Vet</a>
</div>

<div class="pdfs">
  <a href="#" target="_blank"><img src="#" /><br />Connect Platform Catalog</a>
</div>

<div class="pdfs">
  <a href="#" target="_blank"><img src="#" /><br />Instrument Care and Handling</a>
</div>

<div class="pdfs">
  <a href="#" target="_blank"><img src="#" /><br />Opti-Kleen Diamond Knife Cleaning System</a>
</div>

<div class="pdfs">
  <a href="#" target="_blank"><img src="#" /><br />Portables Brochure</a>
</div>

<div class="pdfs">
  <a href="#" target="_blank"><img src="#" /><br />Surgical Disposable Catalog</a>
</div>

<div class="pdfs">
  <a href="#" target="_blank"><img src="#" /><br />PachPen Study</a>
</div>

<div class="pdfs">
  <a href="#" target="_blank"><img src="#" /><br />AccuPen Paper</a>
</div>

<div class="pdfs">
  <a href="#" target="_blank"><img src="#" /><br />Femtosecond Cataract Instruments</a>
</div>

这是CSS:

.pdfs {
  width:22%;
  margin-right:10px;
  margin-bottom:10px;
  float:left;
}

.pdfs:after {
  content:"";
  display:table;
  clear:both;
}

.pdfs img {width:100%;}

最佳答案

不确定你的 :after 规则是干什么用的,但我会用:

.pdfs:nth-child(4n+5) {
    clear:both
}

jsFiddle example

关于html - float div 未正确换行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28724053/

相关文章:

javascript - JavaScript Blob 对象什么时候被垃圾回收?

javascript - 在不移动页面 View 的情况下显示隐藏的div

css - 当 CSS 可见属性为 false 时,Firefox 中的控件是否会接收鼠标事件?

CSS <label> 在 IE9 中 float

css - Wordpress .entry-content 类不会与侧边栏正确对齐

html - 并排放置div

javascript - 将值从 javascript 传递到 html

java - 如何将数据从java后端传递到html页面?

html - CSS 菜单未正确对齐

html - 希望内部 DIV 以 100% 高度和页脚在左侧面板中滚动