layui 布局 高度不一致时导致的错乱问题解决

这个问题找了很久,因为需求是要类似于瀑布流那样的布局,但是因为用的是layui所以又不想弃用,单独写,所以有了以下解决方案:

html:

<div class="layui-row list-body">

<div class="layui-col-md6 list-wrap">

<div class="layui-card list">

  <div class="layui-card-header text-header">

    <div class="layui-clear">

      <span class="title fl">标题题题题题题题题题题题题</span>

      <button class="layui-btn layui-btn-primary post-need fr">按钮</button>

    </div>

    <p class="intro">文字编辑文字编辑文字编辑文字编辑文字编辑</p>

  </div>

  <div class="layui-card-body text-body">

    <p>文字编辑文字编辑文字编辑文字编辑文字编辑文字编辑文字编辑文字编辑文字编辑文字编辑文字编辑文字编辑文字编辑文字编辑文字编辑文字编辑文字编辑文字编辑文字编辑文字编辑文字编辑文字编辑文字编辑文字编辑文字编辑文字编辑文字编辑文字编辑文字编辑文字编辑文字编辑文字编辑文字编辑文字编辑文字编辑文字编辑文字编辑文字编辑文字编辑文字编辑文字编辑文字编辑文字编辑文字编辑文字编辑文字编辑文字编辑文字编辑文字编辑文字编辑文字编辑</p>

  </div>

</div>

</div>

<div class="layui-col-md6 list-wrap">

<div class="layui-card list">

  <div class="layui-card-header text-header">

    <div class="layui-clear">

      <span class="title fl">标题题题题题题题题题题题题</span>

      <button class="layui-btn layui-btn-primary post-need fr">按钮</button>

    </div>

    <p class="intro">文字编辑文字编辑文字编辑文字编辑文字编辑</p>

  </div>

  <div class="layui-card-body text-body">

    <p>文字编辑文字编辑文字编辑文字编辑文字编辑文字编辑文字编辑文字编辑文字编辑文字编辑文字</p>

  </div>

</div>

</div>

<div class="layui-col-md6 list-wrap">

<div class="layui-card list">

  <div class="layui-card-header text-header">

    <div class="layui-clear">

      <span class="title fl">标题题题题题题题题题题题题</span>

      <button class="layui-btn layui-btn-primary post-need fr">按钮</button>

    </div>

    <p class="intro">文字编辑文字编辑文字编辑文字编辑文字编辑</p>

  </div>

  <div class="layui-card-body text-body">

    <p>文字编辑文字编辑文字编辑文字编辑文字编辑文字编辑文字编辑文字编辑文字编辑文字编辑文字编辑文字编辑文字编辑文字编辑文字编辑文字编辑文字编辑文字编辑文字编辑文字编辑文字编辑文字编辑文字编辑文字编辑文字编辑文字编辑文字编辑文字编辑文字编辑文字编辑文字编辑文字编辑文字编辑文字编辑文字编辑文字编辑文字编辑文字编辑文字编辑文字编辑文字编辑文字编辑文字编辑文字编辑文字编辑文字编辑文字编辑文字编辑文字编辑文字编辑文字编辑文字编辑文字编辑文字编辑文字编辑文字编辑文字编辑文字编辑文字编辑文字编辑文字编辑文字编辑文字编辑文字编辑文字编辑文字编辑文字编辑文字编辑文字编辑文字编辑文字编辑文字编辑文字编辑文字编辑文字编辑文字编辑文字编辑文字编辑文字编辑文字编辑文字编辑文字编辑<</p>

  </div>

</div>

</div>

<div class="layui-col-md6 list-wrap">

<div class="layui-card list">

  <div class="layui-card-header text-header">

    <div class="layui-clear">

      <span class="title fl">标题题题题题题题题题题题题</span>

      <button class="layui-btn layui-btn-primary post-need fr">按钮</button>

    </div>

    <p class="intro">文字编辑文字编辑文字编辑文字编辑文字编辑</p>

  </div>

  <div class="layui-card-body text-body">

    <p>文字编辑文字编辑文字编辑文字编辑文字编辑文字编辑文字编辑文字编辑文字编辑文字编辑文字编辑文字编辑文字编辑文字编辑文字编辑文字编辑文字编辑文字编辑文字编辑文字编辑文字编辑文字编辑文字编辑文字编辑文字编辑文字编辑文字编辑文字编辑文字编辑文字编辑文字编辑文字编辑文字编辑文字编辑文字编辑文字编辑文字编辑文字编辑文字编辑文字编辑文字编辑文字编辑文字编辑文字编辑文字编辑文字编辑文字编辑文字编辑文字编辑文字编辑文字编辑</p>

  </div>

</div>

</div>

</div>

css:

.text-banner{

    text-align: center;

}

.text-banner h3{

    font-size: 24px;

    color: #333;

    font-weight: 500;

    margin-top: 25px;

}

.text-banner p{

    font-size: 14px;

    color: #999;

    line-height: 22px;

    margin-top: 16px;

    text-align: left;

    width: 900px;

    margin: 16px auto auto;

}

.text-banner .go-feedback{

    margin-top: 20px;

    margin-bottom: 15px;

}

.text-header{

    height: unset;

    line-height: unset;

    padding: 15px 15px 15px 15px;

    border-bottom: 1px solid #E0E0E0;

}

.text-header .title{

    font-size: 16px;

    color: #333;

    line-height: 30px;

    width: calc(100% - 74px);

    white-space: nowrap;

    overflow: hidden;

    text-overflow: ellipsis;

}

.layui-btn.post-need{

    display: none;

    border-color: #499DFF;

    color: #499DFF;

    height: 30px;

    line-height: 30px;

    padding: 0 12px;

    font-size: 12px;

    width: 74px;

    margin: 0 auto;

}

.post-need:hover{

    background-color: #499DFF;

    color: #fff;

}

.text-header .intro{

    font-size: 13px;

    color: #999;

}

.list:hover .post-need{

    display: block;

}

.list-wrap .list .text-body{

    margin-bottom: 10px;

}

.list-wrap .list .text-body{

    padding: 15px 20px 15px 20px;

}

.list-wrap .list .text-body p{

    font-size: 14px;

    color: #666;

    line-height: 30px;

    text-indent: 24px;

}

//重要的两句代码

.list-body{

    columns: 2;

    margin: 15px 0;

}

.list-body .list-wrap{

    width: 100%;

    -moz-page-break-inside: avoid;

    -webkit-column-break-inside: avoid;

    break-inside: avoid;

}

©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

相关阅读更多精彩内容

  • 在5+app的index.html页通过链接访问自己的vue项目,从而实现打包时,只有一个链接,在更新代码时,只需...
    但行好事code阅读 8,889评论 0 4
  • CSS全称为“层叠样式表 (Cascading Style Sheets)”,它主要是用于定义HTML内容在浏览器...
    凶猛老鹰阅读 2,299评论 0 0
  • 一 外部式css样式 (也可称为外联式)就是把css代码写一个单独的外部文件中,这个css样式文件以“.css...
    KunMitnic阅读 4,640评论 0 1
  • 本文主要讲述页面布局样式方面涉及的知识点,更全面的对CSS相应的技术进行归类、整理、说明,没有特别详细的技术要点说...
    Joel_zh阅读 4,722评论 0 1
  • 一、CSS入门 1、css选择器 选择器的作用是“用于确定(选定)要进行样式设定的标签(元素)”。 有若干种形式的...
    宠辱不惊丶岁月静好阅读 5,570评论 0 6

友情链接更多精彩内容