## **字體屬性簡寫 font**
[**font**](#font): (簡寫)在一個聲明中設置所有的字體屬性
用法1、可以用來作為 font-style, font-variant, font-weight, **font-size**(必須), line-height 和 **font-family**(必須) 屬性的簡寫,
可設置的屬性是(按順序): "font-style font-variant font-weight font-size/line-height font-family"
~~~
p.span{
????font:15px?arial,sans-serif;
}
p.span{
??? font: italic small-caps bold 16px/2 cursive;
}
~~~
## **所有CSS字體屬性**
| 屬性 | 描述 |
| -- | -- |
| [ font-style](#font-style) | 指定文本的字體樣式,值:normal(常規)、italic(斜體)、oblique(傾斜體)、inherit(繼承父元素) |
| [ font-variant](#font-variant) | 以小型大寫字體或者正常字體顯示文本。,兩個值normal(默認)和small-caps <br>small-caps 讓字母以小型方式顯示大寫<br>normal字母處于small-caps時恢復正常小寫狀態|
|[ font-weight](#font-weight) | 指定字體的粗細,從600開始就能明顯看出粗體效果。值:normal(400)、bold(700)、bolder、lighter、100、200、300、400、500、600、700、800、900、inherit |
|[ font-size](#font-size) | 指定文本的字體大小 |
|[ line-height](#line-height) | 指定字體的粗細。 |
|[ font-family](#font-family) | 指定文本的字體系列 |
用法2、將元素的字體設置為系統字體
>[danger]如果將 font 指定為系統關鍵字,則它必須是以下之一:caption, icon, menu, message-box, small-caption, status-bar。
| 系統字體 | 描述 |
| --- | --- |
|caption |定義被標題控件(比如按鈕、下拉列表等)使用的字體。|
|icon |定義被圖標標記使用的字體。|
|menu |定義被下拉列表使用的字體。|
|message-box |定義被對話框使用的字體。|
|small-caption |caption字體的小型版本。|
|status-bar |定義被窗口狀態欄使用的字體。|
~~~
p.span{
????font:small-caption;
}
~~~
| 屬性 | 描述 |
| -- | -- |
| [ @font-face ](#@font-face )| 自定義自己的 Web?字體 |
~~~
@font-face {
[ font-family: <family-name>; ] ||
[ src: <src>; ] ||
[ unicode-range: <unicode-range>; ] ||
[ font-variant: <font-variant>; ] ||
[ font-feature-settings: <font-feature-settings>; ] ||
[ font-variation-settings: <font-variation-settings>; ] ||
[ font-stretch: <font-stretch>; ] ||
[ font-weight: <font-weight>; ] ||
[ font-style: <font-style>; ]
}
~~~
| 字體描述 | 值 | 說明 |
| --- | --- | --- |
| font-family | name | 必需的【IE6】。定義字體的名稱 |
| src | url | 必需的【IE6】。定義該字體下載的網址 |
| font-stretch | `normal`,`condensed`,`ultra-condensed`,`extra-condensed`,`semi-condensed`,`expanded`,`semi-expanded`,`extra-expanded`,`ultra-expanded` | 可選【IE9 Safari不支持】。定義該字體應該如何被拉長。默認值是"正常" |
| font-style | `normal`,`italic`,`oblique` | 可選【IE4】。定義該字體應該是怎樣樣式。默認值是"正常" |
| font-weight | `normal`,`bold`,`100`,`200`,`300`,`400`,`500`,`600`,`700`,`800`,`900` | 可選【IE4】。定義字體的粗細。默認值是"正常" |
| unicode-range | unicode-range | 可選【IE9】。在該@font-face中定義該字體支持Unicode字符的范圍。默認值是"ü+0-10 FFFF" |
| [font-variant](#font-variant) | 兩個值normal(默認)和small-caps <br>small-caps 讓字母以小型方式顯示大寫(即大寫字母和小寫字母一樣大)<br>normal字母處于small-caps時恢復正常小寫狀態 | 可選,以小型大寫字體或者正常字體顯示文本。 |
| [font-feature-settings](https://developer.mozilla.org/zh-CN/docs/Web/CSS/font-feature-settings) | normal 或者 string 1(on)/0(off) | 可選【IE10】,用于控制OpenType字體中的高級印刷功能 |
| [font-variation-settings](https://developer.mozilla.org/zh-CN/docs/Web/CSS/font-variation-settings) | | 可選【IE不支持】,對[variable font](https://developer.mozilla.org/en-US/docs/Web/CSS/CSS_Fonts/Variable_Fonts_Guide)特征的低級控制,通過指定要更改的特征的四個字母軸名稱及其值 |
format:指示瀏覽器對加載的這個字體用什么格式去解析,一般瀏覽器都能自動識別,加上是保險起見

### 設置字體
```
//定義多個字體重復font-face即可
@font-face {
font-family:?myFirstFont;
src:?url('http://www.w3cschool.css/css3/Sansation_Light.ttf') format("truetype");
}
@font-face {
font-family: 'iconfont';/*聲明一個名為iconfont的字體變量*/
src: url('../font/iconfont.eot');
src: url('../font/iconfont.eot?#iefix') format('embedded-opentype'),
url('../font/iconfont.woff2') format('woff2'),
url('../font/iconfont.woff') format('woff'),
url('../font/iconfont.ttf') format('truetype'),
url('../font/iconfont.svg#iconfont') format('svg');
}
@font-face { font-family: testfont; src: url("fonts/test.otf") format("opentype"); }
```
通常有以下幾種:truetype opentype truetype-aat embedded-opentype avg等
TrueType格式(.ttf)
Windows和Mac上常見的字體格式 這是一種原始格式 因此并沒有為網頁進行優化處理
瀏覽器支持:IE9+,FireFox3.5+,Chrome4.0+,Safari3+,Opera10+,IOS Mobile Safari4.2+
OpenType格式(.otf)
以TrueType為基礎 也是一種原始格式 但提供了更多的功能
瀏覽器支持:FireFox3.5+,Chrome4.0+,Safari3.1+,Opera10.0+,IOS Mobile Safari4.2+
Web Open Font格式(.woff)
針對網頁進行特殊優化 因此是Web字體中的最佳格式
它是一個開放的TrueType/OpenType的壓縮版 同時支持元數據包的分離
瀏覽器支持:IE9+, FireFox3.5+, Chrome6+, Safari3.6+,Opera11.1+
Embedded Open Type格式(.eot)
IE專用字體格式 可以從TrueType格式創建此格式字體
瀏覽器支持:IE4+
SVG格式(.svg)
基于SVG字體渲染的格式
瀏覽器支持:Chrome4+, Safari3.1+, Opera10.0+, IOS Mobile Safari3.2+
### 使用字體
~~~
body{
font-family:?myFirstFont;/*上面自定義的字體名或者系統自帶的字體名*/
}
~~~
<span id="font-style" style="font-weight: bold;color:blue">font-style</span>
```
<div>
<span style="font-style: normal;">abc123</span>
<span style="font-style: italic;">abc123</span>
<span style="font-style: oblique;">abc123</span>
<span style="font-style: inherit;">abc123</span>
</div>
```
效果:
<div>
<span style="font-style: normal;">ccc</span>
<br>
<span style="font-style: italic;">ccc</span>
<br>
<span style="font-style: oblique;">ccc</span>
<br>
<span style="font-style: inherit;">ccc</span>
<br>
</div>
<span id="font-variant" style="font-weight: bold;color:blue">font-variant</span>
所謂“小型大寫”就是,即與小寫字母一樣高,外形與大寫字母保持一致
```
<span style="font-variant: small-caps;">AAAaaa</span>
<span style="font-variant: normal;">AAAaaa</span>
```
效果:
<div>
<span style="font-variant: small-caps;">AAAaaa</span>
<br>
<span style="font-variant: normal;">AAAaaa</span>
<br>
</div>
<span id="font-weight" style="font-weight: bold;color:blue">font-weight</span>
```
<span style="font-weight: normal">l</span>
<span style="font-weight: bold">l</span>
<span style="font-weight: bolder">l</span>
<span style="font-weight: lighter">l</span>
<br>
<span style="font-weight: 100">l</span>
<span style="font-weight: 200">l</span>
<span style="font-weight: 300">l</span>
<span style="font-weight: 400">l</span>
<span style="font-weight: 500">l</span>
<span style="font-weight: 600">l</span>
<span style="font-weight: 700">l</span>
<span style="font-weight: 800">l</span>
<span style="font-weight: 900">l</span>
```
效果:
<div>
<span style="font-weight: normal">l</span>
<span style="font-weight: bold">l</span>
<span style="font-weight: bolder">l</span>
<span style="font-weight: lighter">l</span>
<br>
<span style="font-weight: 100">l</span>
<span style="font-weight: 200">l</span>
<span style="font-weight: 300">l</span>
<span style="font-weight: 400">l</span>
<span style="font-weight: 500">l</span>
<span style="font-weight: 600">l</span>
<span style="font-weight: 700">l</span>
<span style="font-weight: 800">l</span>
<span style="font-weight: 900">l</span>
</div>
<span id="font-size" style="font-weight: bold;color:blue">font-size</span>
<span id="line-height" style="font-weight: bold;color:blue">line-height</span>
<span id="font-family" style="font-weight: bold;color:blue">font-family</span>
font-family 可以把多個字體名稱作為一個"回退"系統來保存。如果瀏覽器不支持第一個字體,則會嘗試下一個
屬性值用逗號隔開。瀏覽器會選擇列表中第一個該計算機上有安裝的字體,或者是通過 @font-face 指定的可以直接下載的字體
有兩種類型的字體系列名稱:
1、family-name - 指定的系列名稱:具體字體的名稱(字體格式),比如:"times"、"courier"、"arial"、"微軟雅黑"、"華文彩云"。
華文彩云效果:

2、generic-family - 通常字體系列名稱(字體分類):比如:"serif"、"sans-serif"、"cursive"、"fantasy"、"monospace"。
花
serif:襯線字體,每個字的筆畫末端都帶有以惡搞小勾

sans-serif:非襯線字體

monospace:等寬字體
cursive:草書字體

fantasy:虛幻字體

多個字體用逗號隔開,優先級從前到后,一般字體類別放到最后作為兜底前面字體都沒有的情況下選擇這個類別下存在的任何一個字體
```
p{
font-family:"Times New Roman",Georgia,Serif;
}
```
一般微軟雅黑為第一選擇,用戶能不來了個顯示字體,取決于用戶的電腦是否安裝了這個字體(微軟雅黑是window自帶的),如果實在想要用偏門的字體,那么就需要在css引入該字體
##
使用自己用@font-face設置的字體(這里設置字體就需要注意版權問題啦)
```
@font-face {
font-family:?myFirstFont;//自定義引入的字體名
src:?url('http://www.w3cschool.css/css3/Sansation_Light.ttf') format("truetype");
}
```
一般ttf格式絕大部分瀏覽器都支持,但是說不定那個奇葩就不支持呢,所以我們要引入其他格式(如svg、)

使用此字體(這里是建議用戶使用哪個字體)
~~~
body{
font-family:?myFirstFont;
}
~~~
推薦
```
font-family: "Helvetica Neue", Helvetica, "PingFang SC", Tahoma, "Hiragino Sans GB", "Heiti SC", Arial, "Microsoft YaHei", "WenQuanYi Micro Hei", sans-serif;
```
- CSS
- 達到指定寬度加載css
- 選擇器
- CSS 函數
- @media媒體查詢
- 字體
- 圖標字體
- 文本
- 光標樣式cursor
- 盒子模型
- 溢出(overflow)
- 邊框
- 不透明度opacity
- 背景(background)與漸變xx-gradient
- 輪廓(outline)與 陰影(box-shadow)
- 過渡屬性(Transition)
- 動畫屬性(Animation)
- transform變形效果旋轉,縮放,移動,傾斜等
- 顯示、隱藏與禁用
- box-sizing與resize
- 居中對齊
- css水平居中
- css垂直居中
- 文字與相鄰的元素垂直對齊
- 布局
- 高度塌陷和外邊距重疊最終解決方案
- 解決float布局時高度塌陷的最終方案after偽類元素
- 子/父元素外邊距重疊最終解決方案before偽類元素
- 傳統布局
- position布局
- position水平居中
- position垂直居中
- position水平垂直居中
- 浮動布局
- 高度塌陷和BFC
- clear
- BFC概念及觸發條件
- 表格布局
- 盒子模型布局
- 盒子水平居中布局(如margin:0 auto)
- 盒子垂直居中布局
- 相鄰元素外邊距重疊
- 行內元素的盒子模型
- 彈性伸縮布局flex
- 舊版本(IE不支持)
- 混合過渡版(僅IE10+生效)
- flex布局(新版)
- 多列布局columns
- grid網格布局(實驗性)
- 應用與總結
- 瀑布流布局
- 流式布局(響應式布局又叫百分比布局移動端一般采用)
- 用戶不能鼠標左鍵選擇文本
- 表格
- 表單
- radio
- textarea
- select
- a連接
- ul>li有序列表與ol>li無序列表
- 偽元素
- 容器寬高100%
- 瀏覽器四大內核及前綴
- 移動端開發
- 長度單位與移動端
- css_移動端開發
- rem具體解決方案
- vw具體解決方案
- 兼容性問題
- 瀏覽器默認樣式
- css預處理器
- less
- sass
- stylus
- HTML
- 標簽元素
- head的子標簽
- 文檔元素
- 文本元素
- 嵌入元素
- 分組元素
- 表格元素
- 表單元素
- input
- 標簽元素的屬性
- 全局屬性
- aria-*
- 事件on*
- data-*
- id
- class
- hidden
- style
- title
- draggable
- dropzone(實驗性)
- dir
- autocapitalize
- contenteditable
- lang
- inputmode
- accesskey
- contextmenu(移除)
- exportparts(實驗性)
- is
- itemid
- itemprop
- itemref
- itemscope
- itemtype
- XHTML遺留xml:lang和xml:base
- part(實驗性)
- slot
- spellcheck(實驗性)
- tabindex
- translate
- HTML字符實體
- 行內元素
- iframe和父頁面相互傳值,并兼容跨域問題
- a標簽嵌套解決方案
- JS
- 獲取寬度(offsetParent、clientWidth、clientHeight、offsetWidth、offsetheight、scrollWidth、scrollHeight、offsetTop、offsetLeft、scrollTop、scrollLeft)
- demo
- 全選和反選
- 定時器:
- 哪些HTML元素可以獲得焦點?
- 事件例子
- 鼠標事件
- 注冊條款
- 獲取鼠標坐標
- div跟隨鼠標移動
- 拖拽01
- 鼠標滾動事件
- 鍵盤事件
- 檢查標簽是否含有某個類
- 輪播圖
- 數組的 交集 差集 補集 并集
- 精確計算插件
- 搖獎機
- 移動端跳轉
- 基礎
- js的數據類型
- 基本類型聲明
- 引用類型聲明及用法
- 數組
- 函數
- 對象及函數原型對象
- 繼承
- js的垃圾回收機制
- javascript擴展自定義方法
- 類型轉換
- 作用域(執行上下文)及遞歸調用
- javascript事件
- 連續調用
- 排序
- 內存溢出與內存泄漏
- 系統對象
- 內置對象
- 值屬性
- Infinity
- NaN
- undefined
- globalThis
- Function 屬性
- eval()
- isFinite()
- isNaN()
- parseFloat()
- parseInt()
- decodeURI()
- decodeURIComponent()
- encodeURI()
- encodeURIComponent()
- 基本對象(Object,Function,Boolean,Symbol)
- Object
- defineProperty()
- Function
- Boolean
- Symbol
- 數字和日期對象
- Number
- Date
- BigInt
- Math
- 控制抽象化
- AsyncFunction
- Generator
- GeneratorFunction
- Promise
- Web組裝
- WebAssembly
- 結構化數據(JSON等)
- ArrayBuffer
- Atomics
- DataView
- JSON
- SharedArrayBuffer
- 使用鍵的集合對象
- Map
- Set
- WeakMap
- WeakSet
- 反射
- Reflect
- Proxy
- 可索引的集合對象(數組在這)
- Array數組
- BigInt64Array
- BigUint64Array
- Float32Array
- Float64Array
- Int16Array
- Int32Array
- Int8Array
- Uint8ClampedArray
- Uint8Array
- Uint16Array
- Uint32Array
- 國際化
- Intl
- Intl.Collator
- 文本處理(字符串與正則)
- RegExp
- String
- 錯誤對象
- Error
- InternalError
- AggregateError 實驗性
- EvalError
- RangeError
- ReferenceError
- SyntaxError
- URIError
- TypeError
- null
- TypedArray
- escape()移除但還兼容
- unescape()移除但還生效
- uneval()非標準
- arguments
- 宿主對象(DOM與Browser)
- Browser瀏覽器對象(BOM)
- Window 對象
- History 對象
- Location 對象
- Navigator 對象
- Screen 對象
- 存儲對象(localStorage與sessionStorage)
- DOM 節點對象
- EventTarget
- Node節點對象
- Document文檔節點
- HTMLDocument(HTML對象 )
- HTML 元素接口
- Element元素節點
- Attr屬性對象(與NamedNodeMap )
- DocumentType
- DocumentFragment文檔片段節點
- CharacterData
- Comment
- Text
- CDATASection
- 事件對象Event
- on-event處理器
- CustomEvent
- MouseEvent
- DragEvent
- 手勢(TouchEvent觸摸事件)
- 其他類型事件對象...
- CSSStyleDeclaration 對象
- HTMLCollection
- console對象
- MutationObserver
- 其他重要的對象(FormData與原生Ajax)
- FormData表單對象
- ajax XMLHttpRequest
- 表達式和運算符
- 算術運算符
- 賦值運算符
- 按位操作符
- 逗號操作符
- 比較操作符
- 條件運算符
- 解構賦值
- 函數表達式
- 圓括號運算符
- 邏輯運算符
- Nullish 合并操作符
- 對象初始化
- 運算符優先級
- 可選鏈
- 管道操作符 實驗性
- 屬性訪問器
- 展開語法
- 異步函數表達式
- await
- 類表達式
- delete 操作符
- function* 表達式
- in
- instanceof
- new 運算符
- new.target
- super
- this
- typeof
- void 運算符
- yield
- yield*
- 語句和聲明
- export
- default
- 控制流
- block
- break
- continue
- empty
- if...else
- switch
- throw
- try...catch
- 聲明
- const
- let
- var 描述
- 函數和類
- async function
- class
- function
- function*
- return
- 迭代
- do...while
- for
- for await...of
- for...in
- for...of
- while
- 其他
- debugger
- label
- with 移除但生效
- import
- import.meta
- 函數
- 箭頭函數
- 默認參數值
- 方法的定義
- 剩余參數
- Arguments 對象
- getter
- setter
- 類
- 類私有域
- 類元素
- 構造方法
- extends
- static
- Errors
- 更多
- 已廢棄的特性
- JavaScript 數據結構
- 詞法文法
- 屬性的可枚舉性和所有權
- 迭代協議
- 嚴格模式
- 切換到嚴格模式
- 模板字符串
- ES6(ES2015)
- Es6函數寫法
- 類class
- 導入導出模塊
- 兼容ES5
- 變量聲明
- Symbol新數據類型
- 迭代器(自定義遍歷數組)
- 生成器
- Promise異步編程
- set(集合)
- Map
- 數組新增4個方法
- 手機端事件
- bootstrap手冊
- 代碼壓縮打包
- Webpack
- 五個核心概念
- 開始
- loader
- 插件
- webpack開發環境配置
- 打包含css文件的項目
- 打包html資源
- 打包圖片資源
- 打包其他文件
- devServer(實時自動化打包)
- 總結:開發環境配置
- webpack生產環境配置
- 提取css成單獨文件
- css兼容性處理
- 壓縮css
- js語法檢查
- js兼容性處理
- js壓縮
- html壓縮
- 總結:生產環境配置
- webpack優化環境配置
- HMR( 模塊熱替換)
- source-map
- oneOf
- 緩存
- tree shaking
- code split
- demo1
- demo2
- demo3
- lazy loading
- pwa
- 多進程打包
- externals
- dll
- webpack配置詳解
- entry
- output
- module
- resolve
- dev server
- optimization
- vite
- 技能
- 前端學習路線
- 調試
- 多個版本IE瀏覽器(調試用)
- 手機端調試
- vueJS
- Element UI(一個vuejs組件)
- 瀏覽器插件開發
- 插件推薦
- 擴展文件manifest.json
- 不可視的background(常駐)頁面
- 可視頁面browser actions與page actions及八種展示方式
- 使用chrome.xxx API
- Google Chrome擴展與Web頁面/服務器之間的交互
- Google Chrome擴展中的頁面之間的數據通信
- inject-script
- chromeAPI
- pageAction
- alarms
- chrome.tabs
- chrome.runtime
- chrome.webRequest
- chrome.window
- chrome.storage
- chrome.contextMenus
- chrome.devtools
- chrome.extension
- 分類
- homepage_url 開發者或者插件主頁
- 5種類型的JS對比及消息通信
- 其它補充
- 谷歌瀏覽器截屏
- 框架及工具
- 前端UI設計網站
- 網頁中使用Unicode字符