微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

html – 停止CSS3列打破段落

在使用 CSS3列时,如何停止浏览器分解段落?我有这个代码
<div class="container">
    <div class="Box"><!-- text --></div>
    <div class="Box"><!-- text --></div>
    <div class="Box"><!-- text --></div>
    <div class="Box"><!-- text --></div>
    <div class="Box"><!-- text --></div>
    <div class="Box"><!-- text --></div>
    <div class="Box"><!-- text --></div>
    <div class="Box"><!-- text --></div>
</div>

.container {
    column-count: 3;
 }

这是我想要的视觉表现.在左边,认情况下会发生什么,在右边,我想要发生什么.

我不介意列是不等长的,重要的是没有任何div在列之间被打破.

解决方法

设置拆分:根据CSS多列布局模块中的 break-inside的描述,避免这样做.但是 browser support是有限的,所以你需要另外使用一些反映旧草稿中的想法的其他设置,在某些浏览器中实现:
.container {
  -moz-column-count: 3;
  -webkit-column-count: 3;
  column-count: 3;
 }
div.Box { 
  text-indent: 1em; /* To show paragraph starts. */
  page-break-inside: avoid; /* For Firefox. */
  -webkit-column-break-inside: avoid; /* For Chrome & friends. */
  break-inside: avoid; /* For standard browsers like IE. :-) */
}
<div class="container">
    <div class="Box">This is a short paragraph.</div>
    <div class="Box">This is a short paragraph,too.</div>
    <div class="Box">This is yet another short paragraph.</div>
    <div class="Box">This is a short paragraph.</div>
    <div class="Box">This,too,is a short paragraph.</div>
    <div class="Box">This is a longer paragraph,which may get divided into two columns..</div>
    <div class="Box">This is a short paragraph.</div>
    <div class="Box">This is a short paragraph.</div>
</div>

原文地址:https://www.jb51.cc/html/228347.html

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐