@font-face嵌入字體
@font-face能夠加載服務器端的字體文件,讓瀏覽器端可以顯示用戶電腦里沒有安裝的字體。
語法:
@font-face { font-family : 字體名稱; src : 字體文件在服務器上的相對或絕對路徑; }
這樣設置之后,就可以像使用普通字體一樣在(font-*)中設置字體樣式。
比如:
p { font-size :12px; font-family : "My Font"; /*必須項,設置@font-face中font-family同樣的值*/}
例子:
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title>嵌入字體</title> <style type="text/css"> @font-face{ font-family: "myFont"; src: url("http://www.imooc.com/Amaranth-BoldItalic.otf"); } .demo { width: 340px; padding: 30px; color: #566F89; background: #000; font-size:58px; font-family: "myFont"; } </style> </head> <body> <div class="demo">myFont</div> </body> </html>
效果:加了字體的: