使用偽類(::before/::after)設置文本前后圖標。減少標簽的浪費,使頁面更加整潔。
如圖:
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title></title> <style type="text/css"> .box{ margin: 20px; padding: 10px 0; border: 1px solid #ededed; text-align: center; } .nonemore,.goodbey{ display: block; font-size: 14px; } /* before設置圖標 */ .nonemore::before{ content: ' '; display: inline-block; width: 20px; height: 20px; background: url(img/face.png) no-repeat; background-size: 20px; vertical-align: top; padding-right: 10px; } /* after設置圖標 */ .goodbey::after{ content: ' '; display: inline-block; width: 20px; height: 20px; background: url(img/face.png) no-repeat; background-size: 20px; vertical-align: top; margin-left: 10px; } </style> </head> <body> <div class="box"> <span class="nonemore">沒有更多了</span> </div> <div class="box"> <span class="goodbey">下次再見哦</span> </div> </body> </html>