前言
電商網站中常會以列表的形式展示商品項,這里參照一些電商網站,將通常使用的結構和樣式小結如下。
商品列表項.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">

</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