css制御文字表示行数

1126 ワード

行を表示

/*       ,    ...  ,  width  ,         */
overflow: hidden;  //      
text-overflow: ellipsis;  //            
white-space: nowrap;  //     

2、複数行の表示制御
/**    :    WebKit CSS    ,      WebKit       ;**/
display: -webkit-box; //               
-webkit-box-orient: vertical; //                   
-webkit-line-clamp: 3;  //             
overflow: hidden; //    

 
3、複数行の表示制御
p{position: relative; line-height: 20px; max-height: 40px;overflow: hidden;}
p::after{content: "..."; position: absolute; bottom: 0; right: 0; padding-left: 40px;
background: -webkit-linear-gradient(left, transparent, #fff 55%);
background: -o-linear-gradient(right, transparent, #fff 55%);
background: -moz-linear-gradient(right, transparent, #fff 55%);
background: linear-gradient(to right, transparent, #fff 55%);
}

 
  • heightをline-heightの整数倍に設定し、文字の露出を防止します.
  • p::afterにグラデーションバックグラウンドを追加すると、文字が半分しか表示されないことを回避できます.
  • ie 6-7はcontentコンテンツを表示しないため、ラベル互換ie 6-7を追加します(例えば:...).互換ie 8は、afterをafter
  • に置き換える必要がある.