HTML/CSS实现账单吸顶效果

效果

image.png

案例:

<!DOCTYPE html>
<html>
  <head>
    <meta charset="utf-8">
    <meta name="apple-mobile-web-app-capable" content="yes" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=0, viewport-fit=cover" />
    <title>sticky粘性效果</title>
    <!--
      @author: SM
      @email: sm0210@qq.com
      @desc 账单吸顶效果
    -->
    <!--
        css
    -->
    <style type="text/css">
     *,*::after,*::before {
        margin: 0px;
        padding: 0px;
        -webkit-tap-highlight-color: transparent;
        -webkit-input-placeholder-color: transparent;
        -webkit-overflow-scrolling: touch;
        outline: none;
      }
      body {
        font-family: "PingFang SC", "苹方", "PingFangSC-Regular", "Helvetica Neue",Helvetica,STHeiTi,sans-serif;
        -moz-user-select: none;
        -webkit-user-select: none;
        -ms-user-select: none;
        -khtml-user-select: none;
        user-select: none;
        -ms-touch-action: none;
        color: #676767;
        background: #fff;
        font-size: 14px;
      }
      ul, li {
        list-style: none;
      }
      /*
              弹性盒
          */
      .box-flex {
        display: -webkit-box;
      }
      .box-flex-1{
        -webkit-box-flex: 1;
      }

      .padding-lf-15 {
        padding-left: 16px;
        padding-right: 16px;
      }
      .font-size-12 {
        font-size: 12px;
      }

      .filter_content {
        height: 42px;
        line-height: 42px;
        border-bottom: 1px solid #ccc;
        background-color: #fff;
        transition:0.4s ease;
        position: sticky;
        top: 0px;
        z-index: 10;
      }
      .filter_info {
        position: relative;
      }
      .filter_info span {
        display: inline-block;
      }
      .filter_info span:after {
        content: '';
        margin-left: 10px;
        width: 0;
        height: 0;
        position: absolute;
        top: 18px;
        border-width: 5px;
        border-style: solid;
        border-color: #ccc transparent transparent transparent;
      }
      .filter_info span:first-child {
        margin-right: 60px;
      }
      .filter_search:before {
        content: '';
        border-left: 1px solid #ccc;
        position: absolute;
        height: 16px;
        margin-left: -15px;
        top: 13px;
      }
      /*
              明细
          */
      .bill_detail_month {
        height: 70px;
        background-color: #F6F6F6;
        /* 粘性效果 */
        transition:0.4s ease;
        position: sticky;
        z-index: 9;
        top: 42px;
        border-bottom: 1px solid #F1F1F1;
      }
      .bill_detail_month .bill_detail_month_text {
        min-width: 58px;
        height: 26px;
        line-height: 26px;
        background-color: #fff;
        -webkit-border-radius: 40px;
        margin-top: 23px;
        padding-left: 12px;
        position: relative;
      }

      .bill_detail_month .bill_detail_month_text:after {
        content: '';
        border: 1px solid red;
        position: absolute;
        right: 15px;
        top: 12px;
        border-width: 5px;
        border-style: solid;
        border-color: #ccc transparent transparent transparent;
      }

      .bill_detail_month .bill_detail_text {
        padding-top: 15px;
        text-align: right;
        color: #B4B4B4;
        font-size: 14px;
      }
      /*
              消费明细
          */
      .bill_detail_info {
        height: 112px;
      }
      .bill_detail_info_icon {
        line-height: normal;
        width: 40px;
        height: 40px;
        text-align: center;
        line-height: 40px;
        -webkit-border-radius: 40px;
        margin-top: 36px;
      }
      .bill_detail_info_money {
        margin-top: 36px;
        width: 110px;
        text-align: right;
        color: #353535;
        font-weight: bold;
        font-size: 18px;
      }
      /*
              收入
          */
      .bill_detail_info_money.income {
        color: #EB4D30;
      }
      /*
              图标
          */
      .bill_detail_info_icon.elm {
        background-color: #0C9EFA;
      }

      .bill_detail_info_icon.zs {
        background-color: #E00611;
      }

      .bill_detail_info_icon.yeb {
        background-color: #E95621;
      }
      .bill_detail_info_icon.tk {
        background-color: #178EE0;
      }

      .bill_detail_info_icon.tb {
        background-color: #FC4603;
      }

      .bill_detail_info_icon_content {
        margin-left: 20px;
        margin-top: 36px;
      }
      .bill_detail_info_icon_content li {
        line-height: 22px;
        color: #5D5D5D;
      }
      .bill_detail_info_1px {
        border-bottom: 1px solid #ccc;
      }
      .bill_detail_info:last-child .bill_detail_info_1px {
        border-bottom: none;
      }
      .bill_detail_info_date {
        color: #A4A4A4;
      }
    </style>
  </head>
  <body>
    <!-- box -->
      <div class="box">
        <!-- 筛选/分类 -->
        <div class="box-flex padding-lf-15 filter_content">
          <div class="box-flex-1 filter_info "><span>筛选</span><span>分类</span></div>
          <div class="filter_search">搜索</div>
        </div>
        <!--明细-->
        <div class="bill_detail">
          <!-- 月份 -->
          <div class="box-flex padding-lf-15 bill_detail_month">
            <div class="bill_detail_month_text">本月</div>
            <div class="box-flex-1 bill_detail_text">
              <ul>
                <li>支出 ¥1,250.03</li>
                <li>收入 ¥144.55</li>
              </ul>
            </div>
          </div>
          <!-- 具体明细 -->
          <div class="box-flex padding-lf-15 bill_detail_info">
            <div class="bill_detail_info_icon zs"></div>
            <div class="box-flex-1 box-flex bill_detail_info_1px">
              <div class="box-flex-1 bill_detail_info_icon_content">
                <ul>
                  <li>信用卡还款-银行</li>
                  <li class="font-size-12">借还款</li>
                  <li class="bill_detail_info_date font-size-12">03-28 18:19</li>
                  </ul>
              </div>
              <div class="bill_detail_info_money">-297.84</div>
            </div>
          </div>

          <div class="box-flex padding-lf-15 bill_detail_info">
            <div class="bill_detail_info_icon elm"></div>
            <div class="box-flex-1 box-flex bill_detail_info_1px">
              <div class="box-flex-1 bill_detail_info_icon_content">
                <ul>
                  <li>黄焖鸡米饭(XX快餐)</li>
                  <li class="font-size-12">饮食</li>
                  <li class="bill_detail_info_date font-size-12">03-28 18:19</li>
                  </ul>
              </div>
              <div class="bill_detail_info_money">-11.40</div>
            </div>
          </div>

          <div class="box-flex padding-lf-15 bill_detail_info">
            <div class="bill_detail_info_icon yeb"></div>
            <div class="box-flex-1 box-flex bill_detail_info_1px">
              <div class="box-flex-1 bill_detail_info_icon_content">
                <ul>
                  <li>某额宝-收益</li>
                  <li class="font-size-12">理财</li>
                  <li class="bill_detail_info_date font-size-12">03-28 18:19</li>
                  </ul>
              </div>
              <div class="bill_detail_info_money income">+0.94</div>
            </div>
          </div>

          <div class="box-flex padding-lf-15 bill_detail_info">
            <div class="bill_detail_info_icon tk"></div>
            <div class="box-flex-1 box-flex bill_detail_info_1px">
              <div class="box-flex-1 bill_detail_info_icon_content">
                <ul>
                  <li>退款-商品</li>
                  <li class="font-size-12">交通出行</li>
                  <li class="bill_detail_info_date font-size-12">03-28 18:19</li>
                  </ul>
              </div>
              <div class="bill_detail_info_money income">+6.54</div>
            </div>
          </div>

          <div class="box-flex padding-lf-15 bill_detail_info">
            <div class="bill_detail_info_icon tb"></div>
            <div class="box-flex-1 box-flex bill_detail_info_1px">
              <div class="box-flex-1 bill_detail_info_icon_content">
                <ul>
                  <li>商品购买</li>
                  <li class="font-size-12">交通出行</li>
                  <li class="bill_detail_info_date font-size-12">03-28 18:19</li>
                  </ul>
              </div>
              <div class="bill_detail_info_money">-10.36</div>
            </div>
          </div>

          <!-- 具体明细end -->

        </div><!-- 账单详情 -->
        <!-- 2月 -->
        <div class="bill_detail">
          <!-- 月份 -->
          <div class="box-flex padding-lf-15 bill_detail_month">
            <div class="bill_detail_month_text">2月</div>
            <div class="box-flex-1 bill_detail_text">
              <ul>
                <li>支出 ¥1,250.03</li>
                <li>收入 ¥144.55</li>
              </ul>
            </div>
          </div>
          <!-- 具体明细 -->
          <div class="box-flex padding-lf-15 bill_detail_info">
            <div class="bill_detail_info_icon zs"></div>
            <div class="box-flex-1 box-flex bill_detail_info_1px">
              <div class="box-flex-1 bill_detail_info_icon_content">
                <ul>
                    <li>信用卡还款-银行</li>
                    <li class="font-size-12">借还款</li>
                    <li class="bill_detail_info_date font-size-12">02-28 18:19</li>
                  </ul>
              </div>
              <div class="bill_detail_info_money">-297.84</div>
            </div>
          </div>

          <div class="box-flex padding-lf-15 bill_detail_info">
            <div class="bill_detail_info_icon elm"></div>
            <div class="box-flex-1 box-flex bill_detail_info_1px">
              <div class="box-flex-1 bill_detail_info_icon_content">
                <ul>
                    <li>黄焖鸡米饭(XX快餐)</li>
                    <li class="font-size-12">饮食</li>
                    <li class="bill_detail_info_date font-size-12">02-28 18:19</li>
                  </ul>
              </div>
              <div class="bill_detail_info_money">-11.40</div>
            </div>
          </div>

          <div class="box-flex padding-lf-15 bill_detail_info">
            <div class="bill_detail_info_icon yeb"></div>
            <div class="box-flex-1 box-flex bill_detail_info_1px">
              <div class="box-flex-1 bill_detail_info_icon_content">
                <ul>
                    <li>某额宝-收益</li>
                    <li class="font-size-12">理财</li>
                    <li class="bill_detail_info_date font-size-12">02-28 18:19</li>
                  </ul>
              </div>
              <div class="bill_detail_info_money income">+0.94</div>
            </div>
          </div>

          <div class="box-flex padding-lf-15 bill_detail_info">
            <div class="bill_detail_info_icon tk"></div>
            <div class="box-flex-1 box-flex bill_detail_info_1px">
              <div class="box-flex-1 bill_detail_info_icon_content">
                <ul>
                    <li>退款-商品</li>
                    <li class="font-size-12">交通出行</li>
                    <li class="bill_detail_info_date font-size-12">02-28 18:19</li>
                  </ul>
              </div>
              <div class="bill_detail_info_money income">+6.54</div>
            </div>
          </div>

          <div class="box-flex padding-lf-15 bill_detail_info">
            <div class="bill_detail_info_icon tb"></div>
            <div class="box-flex-1 box-flex bill_detail_info_1px">
              <div class="box-flex-1 bill_detail_info_icon_content">
                <ul>
                    <li>商品购买</li>
                    <li class="font-size-12">交通出行</li>
                    <li class="bill_detail_info_date font-size-12">02-28 18:19</li>
                  </ul>
              </div>
              <div class="bill_detail_info_money">-10.36</div>
            </div>
          </div>
          <!-- 具体明细end -->
        </div><!--账单详情-->
        <!-- 1月-->
        <div class="bill_detail">
          <!-- 月份 -->
          <div class="box-flex padding-lf-15 bill_detail_month">
            <div class="bill_detail_month_text">1月</div>
            <div class="box-flex-1 bill_detail_text">
              <ul>
                <li>支出 ¥1,250.03</li>
                <li>收入 ¥144.55</li>
              </ul>
            </div>
          </div>
          <!-- 具体明细 -->
          <div class="box-flex padding-lf-15 bill_detail_info">
            <div class="bill_detail_info_icon zs"></div>
            <div class="box-flex-1 box-flex bill_detail_info_1px">
              <div class="box-flex-1 bill_detail_info_icon_content">
                <ul>
                    <li>信用卡还款-银行</li>
                    <li class="font-size-12">借还款</li>
                    <li class="bill_detail_info_date font-size-12">01-28 18:19</li>
                  </ul>
              </div>
              <div class="bill_detail_info_money">-297.84</div>
            </div>
          </div>

          <div class="box-flex padding-lf-15 bill_detail_info">
            <div class="bill_detail_info_icon elm"></div>
            <div class="box-flex-1 box-flex bill_detail_info_1px">
              <div class="box-flex-1 bill_detail_info_icon_content">
                <ul>
                    <li>黄焖鸡米饭(XX快餐)</li>
                    <li class="font-size-12">饮食</li>
                    <li class="bill_detail_info_date font-size-12">01-28 18:19</li>
                  </ul>
              </div>
              <div class="bill_detail_info_money">-11.40</div>
            </div>
          </div>

          <div class="box-flex padding-lf-15 bill_detail_info">
            <div class="bill_detail_info_icon yeb"></div>
            <div class="box-flex-1 box-flex bill_detail_info_1px">
              <div class="box-flex-1 bill_detail_info_icon_content">
                <ul>
                    <li>某额宝-收益</li>
                    <li class="font-size-12">理财</li>
                    <li class="bill_detail_info_date font-size-12">01-28 18:19</li>
                  </ul>
              </div>
              <div class="bill_detail_info_money income">+0.94</div>
            </div>
          </div>

          <div class="box-flex padding-lf-15 bill_detail_info">
            <div class="bill_detail_info_icon tk"></div>
            <div class="box-flex-1 box-flex bill_detail_info_1px">
              <div class="box-flex-1 bill_detail_info_icon_content">
                <ul>
                    <li>退款-商品</li>
                    <li class="font-size-12">交通出行</li>
                    <li class="bill_detail_info_date font-size-12">01-28 18:19</li>
                  </ul>
              </div>
              <div class="bill_detail_info_money income">+6.54</div>
            </div>
          </div>

          <div class="box-flex padding-lf-15 bill_detail_info">
            <div class="bill_detail_info_icon tk"></div>
            <div class="box-flex-1 box-flex bill_detail_info_1px">
              <div class="box-flex-1 bill_detail_info_icon_content">
                <ul>
                    <li>退款-商品</li>
                    <li class="font-size-12">交通出行</li>
                    <li class="bill_detail_info_date font-size-12">01-28 18:19</li>
                  </ul>
              </div>
              <div class="bill_detail_info_money income">+6.54</div>
            </div>
          </div>

          <div class="box-flex padding-lf-15 bill_detail_info">
            <div class="bill_detail_info_icon tk"></div>
            <div class="box-flex-1 box-flex bill_detail_info_1px">
              <div class="box-flex-1 bill_detail_info_icon_content">
                <ul>
                    <li>退款-商品</li>
                    <li class="font-size-12">交通出行</li>
                    <li class="bill_detail_info_date font-size-12">01-28 18:19</li>
                  </ul>
              </div>
              <div class="bill_detail_info_money income">+6.54</div>
            </div>
          </div>

          <!-- 具体明细end -->
        </div><!--账单详情-->

      </div>
    <!-- box -->
  </body>
</html>

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
  • 序言:七十年代末,一起剥皮案震惊了整个滨河市,随后出现的几起案子,更是在滨河造成了极大的恐慌,老刑警刘岩,带你破解...
    沈念sama阅读 216,324评论 6 498
  • 序言:滨河连续发生了三起死亡事件,死亡现场离奇诡异,居然都是意外死亡,警方通过查阅死者的电脑和手机,发现死者居然都...
    沈念sama阅读 92,356评论 3 392
  • 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
    开封第一讲书人阅读 162,328评论 0 353
  • 文/不坏的土叔 我叫张陵,是天一观的道长。 经常有香客问我,道长,这世上最难降的妖魔是什么? 我笑而不...
    开封第一讲书人阅读 58,147评论 1 292
  • 正文 为了忘掉前任,我火速办了婚礼,结果婚礼上,老公的妹妹穿的比我还像新娘。我一直安慰自己,他们只是感情好,可当我...
    茶点故事阅读 67,160评论 6 388
  • 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
    开封第一讲书人阅读 51,115评论 1 296
  • 那天,我揣着相机与录音,去河边找鬼。 笑死,一个胖子当着我的面吹牛,可吹牛的内容都是我干的。 我是一名探鬼主播,决...
    沈念sama阅读 40,025评论 3 417
  • 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...
    开封第一讲书人阅读 38,867评论 0 274
  • 序言:老挝万荣一对情侣失踪,失踪者是张志新(化名)和其女友刘颖,没想到半个月后,有当地人在树林里发现了一具尸体,经...
    沈念sama阅读 45,307评论 1 310
  • 正文 独居荒郊野岭守林人离奇死亡,尸身上长有42处带血的脓包…… 初始之章·张勋 以下内容为张勋视角 年9月15日...
    茶点故事阅读 37,528评论 2 332
  • 正文 我和宋清朗相恋三年,在试婚纱的时候发现自己被绿了。 大学时的朋友给我发了我未婚夫和他白月光在一起吃饭的照片。...
    茶点故事阅读 39,688评论 1 348
  • 序言:一个原本活蹦乱跳的男人离奇死亡,死状恐怖,灵堂内的尸体忽然破棺而出,到底是诈尸还是另有隐情,我是刑警宁泽,带...
    沈念sama阅读 35,409评论 5 343
  • 正文 年R本政府宣布,位于F岛的核电站,受9级特大地震影响,放射性物质发生泄漏。R本人自食恶果不足惜,却给世界环境...
    茶点故事阅读 41,001评论 3 325
  • 文/蒙蒙 一、第九天 我趴在偏房一处隐蔽的房顶上张望。 院中可真热闹,春花似锦、人声如沸。这庄子的主人今日做“春日...
    开封第一讲书人阅读 31,657评论 0 22
  • 文/苍兰香墨 我抬头看了看天上的太阳。三九已至,却和暖如春,着一层夹袄步出监牢的瞬间,已是汗流浃背。 一阵脚步声响...
    开封第一讲书人阅读 32,811评论 1 268
  • 我被黑心中介骗来泰国打工, 没想到刚下飞机就差点儿被人妖公主榨干…… 1. 我叫王不留,地道东北人。 一个月前我还...
    沈念sama阅读 47,685评论 2 368
  • 正文 我出身青楼,却偏偏与公主长得像,于是被迫代替她去往敌国和亲。 传闻我的和亲对象是个残疾皇子,可洞房花烛夜当晚...
    茶点故事阅读 44,573评论 2 353

推荐阅读更多精彩内容