列表的響應式排版,列表響應式排版
效果展示:
一、每行固定個數:保證排版的美觀
.list li{width:20%;display:inline-block;*display:inline;*zoom:1;overflow:hidden;}
二、隨頁面寬度調整個數和大小:保證圖文的可讀性
.list li{width:20%;display:inline-block;*display:inline;*zoom:1;overflow:hidden;}
1、媒體查詢控制寬度
@media screen and (max-width:1280px){ .list-table1 li{width:25%}}@media screen and (max-width:600px){ .list-table1 li{width:33.3%}}@media screen and (max-width:400px){ .list-table1 li{width:50%}}
方便、但存在相容性
2、JS控制
$(window).resize(function () { resizeList();})function resizeList(){ var s_width=$(window).width(); //console.log("s_width:"+s_width); if(s_width>600 && s_width <=1280) { $(".list-table1 li").css("width","25%"); }else if(s_width>400 && s_width <=600){ $(".list-table1 li").css("width","33.3%"); }else if(s_width>200 && s_width <=400){ $(".list-table1 li").css("width","50%"); }else if(s_width<=200){ $(".list-table1 li").css("width","100%"); }}
$(window).resize()即時擷取瀏覽器的寬度
注意事項:
1、圖片不變形
.a-common{width:auto;height:auto;}.a-common img{width:100%;height:auto;}
2、文字溢出處理
.title, .subtitle{width:auto;text-align:center;overflow:hidden;white-space:nowrap;text-overflow:ellipsis;}