@font-face(css3屬性)實現在網頁中嵌入任意字型,@font-facecss3

來源:互聯網
上載者:User

@font-face(css3屬性)實現在網頁中嵌入任意字型,@font-facecss3

@font-face文法規則

@font-face {   font-family: <YourWebFontName>;   src: <source> [<format>][,<source> [<format>]]*;   [font-weight: <weight>];   [font-style: <style>]; }
說明:

  1. YourWebFontName:此值指的就是你自訂的字型名稱,最好是使用你下載的預設字型,他將被引用到你的Web元素中的font-family。如“font-family:"YourWebFontName";”

  2. source:此值指的是你自訂的字型的存放路徑,可以是相對路徑也可以是絕路徑;

format:此值指的是你自訂的字型的格式,主要用來協助瀏覽器識別,其值主要有以下幾種類型:truetype,opentype,truetype-aat,embedded-opentype,avg等;weight和style:這兩個值大家一定很熟悉,weight定義字型是否為粗體,style主要定義字型樣式,如斜體。

執行個體:(以SingleMaltaRegular為例)

  1. 下載所需要的字型。

  2. 獲得@font-face所需的.eot,.woff,.ttf,.svg字型格式字型。可以在這個網站上搞定。點擊進入 (fontsquirrel)

  3. Font Squirrel下載檔案到本地的電腦上了,解壓。即可得到字型。

  4. 在項目中建立檔案夾fonts,講下載字型放進去。

樣式書寫格式:

@font-face {   font-family: 'SingleMaltaRegular';      src: url('../fonts/singlemalta-webfont.eot');     src: url('../fonts/singlemalta-webfont.eot?#iefix') format('embedded-opentype'),         url('../fonts/singlemalta-webfont.woff') format('woff'),      url('../fonts/singlemalta-webfont.ttf') format('truetype'),       url('../fonts/singlemaltawebfont.svg#SingleMaltaRegular') format('svg');   font-weight: normal;   font-style: normal;}


最後即可引用的字型:

body{  font-family: 'SingleMaltaRegular'}

註:通過網站下載的檔案裡,會自動產生樣式,從而直接拷貝即可

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.