HTML - 商品列表项小结(移动端)

前言

电商网站中常会以列表的形式展示商品项,这里参照一些电商网站,将通常使用的结构和样式小结如下。


商品列表项.png

小结:

1.在商品项的最外层包裹a标签,便于用户点击查看详情

a.item-block {
    position: absolute;
    left: 0;
    top: 0;
    width: 100%;
    height: 100%;
}

2.商品(介绍)标题单行显示,溢出隐藏,超出部分显示省略号"..."

.item-title {
    text-overflow: ellipsis; /*省略号*/
    white-space: nowrap; /*文本会显示在同一行,直到遇到 <br> 标签为止*/
    overflow: hidden; /*溢出隐藏*/
}
单行显示.png

3.商品介绍(标题)限制最大行数,超出部分显示省略号"..."

.item-title {
    display: -webkit-box;
    -webkit-line-clamp: 2; /*行数*/
    -webkit-box-orient: vertical;
    word-break: break-all;
    overflow: hidden;
    /*行高和最大高度根据实际设置*/
    line-height: 18px;
    max-height: 36px;
}
多行显示.png

实例 HTML

    <div class="container">
      <!--在商品项的最外层包裹a标签 便于用户点击查看详情-->
      <a href="" class="item-block">
          <div class="item-block-img">
              ![](./2.png)
          </div>
          <div class="item-title">
              12期分期/当天发/Apple/苹果 iPhone 7 Plus国行全网通4G手机
          </div>
          <div class="item-monthsell">
              月销量1494件
          </div>
          <div class="item-price">
              <span class="mui-price">
                  <i>¥</i>
                  <span class="mui-price-inter">5948</span>
              </span>
              <span class="mui-price gray">
                  <i>¥</i>
                  <span class="mui-price-inter">5948.0</span>
              </span>
          </div>
      </a>
    </div>

实例 CSS

    <style>
        *{
            padding: 0;
            margin: 0;
        }
        a{
            overflow: hidden;
            color: #051B28;
            text-decoration: none;
        }
        i{
            font-style: normal;
            font-family: Arial;
        }
        .container{
            position: relative;
            width: 188px;
            height: 304px;
            background: #fff;
            box-sizing: border-box;
            border: 2px solid #ccc;
            margin: 20px 0 0 20px;
        }
        /*在商品项的最外层包裹a标签 便于用户点击查看详情*/
        a.item-block {
            position: absolute;
            left: 0;
            top: 0;
            width: 100%;
            height: 100%;
        }
        .item-block-img img {
            width: 186px;
            height: 186px;
            max-width: 100%;
        }
        .item-title {
            font-size: 14px;
            color: #333;
            display: -webkit-box;
            -webkit-line-clamp: 2;
            -webkit-box-orient: vertical;
            overflow: hidden;
            line-height: 1.2;
            height: 30px;
            max-height: 36px;
            margin: 9px;
        }
        .item-monthsell {
            display: inline-block;
            font-size: 12px;
            max-width: 100%;
            white-space: nowrap;
            color: #999;
            margin: 0 9px 3px;
            height: 18px;
            overflow: hidden;
            text-overflow: ellipsis;
            line-height: 18px;
        }
        .item-price {
            margin: 4%!important;
            height: 5%!important;
        }
        .mui-price {
            color: #dd2727;
            font-size: 12px;
        }
        .mui-price-inter {
            font-size: 16px;
            font-family: Helvetica,sans-serif;
            font-style: normal;
        }
        .mui-price.gray {
            color: #999;
            font-size: 10px;
            text-decoration: line-through;
        }
        .gray .mui-price-inter {
            font-size: 12px;
            font-family: Helvetica,sans-serif;
            font-style: normal;
        }
    </style>
实例效果.png
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • Android 自定义View的各种姿势1 Activity的显示之ViewRootImpl详解 Activity...
    passiontim阅读 173,925评论 25 709
  • Spring Cloud为开发人员提供了快速构建分布式系统中一些常见模式的工具(例如配置管理,服务发现,断路器,智...
    卡卡罗2017阅读 135,083评论 19 139
  • 用两张图告诉你,为什么你的 App 会卡顿? - Android - 掘金 Cover 有什么料? 从这篇文章中你...
    hw1212阅读 13,079评论 2 59
  • 雾深处: 模糊了人,看花了景。 好一个回眸,只为伊人笑。 春心荡落了叶, 那人痴笑了雾。
    Moneyer小姐阅读 342评论 1 1
  • 今天看到一篇関于中醫的訪談,里面提到的中醫理念很精致,很漂亮,但是精致、漂亮到令人憂傷。太理想了,反而容易失敗 甚...
    王玨新派中醫阅读 378评论 1 0