Bootstrap 開源了首套 SVG 圖標(biāo)庫 Bootstrap Icons,其團(tuán)隊表示這是有史以來第一次擁有自己的圖標(biāo)庫,此圖標(biāo)庫起初專門針對其從表單控件到導(dǎo)航等組件和文檔進(jìn)行定制設(shè)計和構(gòu)建,現(xiàn)在可以免費用于任何項目,無論此項目是否使用了 Bootstrap。
查看 Bootstrap Icons »https://icons.getbootstrap.com/
既然 Bootstrap Icons 是 SVG 圖標(biāo)庫,因此它們可以快速、輕松地擴(kuò)展,并且可以配合 CSS 的使用進(jìn)行個性化定制。雖然它們是為 Bootstrap 設(shè)計的,但可以在任何項目中使用。不過要注意的是,它們現(xiàn)在尚處于 alpha 階段,未來可能會出現(xiàn)重大變化。
Bootstrap Icons 官網(wǎng)提供了檢索圖標(biāo)種類的搜索框,用戶可根據(jù)需求使用關(guān)鍵字(英文)進(jìn)行查找。
根據(jù)自己的設(shè)置,可以通過多種方式將 Bootstrap Icons 添加到項目:
-
將 SVG 復(fù)制粘貼為內(nèi)嵌式的 HTML 元素
- <svg class="bi bi-chevron-right" width="32" height="32" viewBox="0 0 20 20" fill="currentColor" xmlns="http://www.w3.org/2000/svg"><path fill-rule="evenodd" d="M6.646 3.646a.5.5 0 01.708 0l6 6a.5.5 0 010 .708l-6 6a.5.5 0 01-.708-.708L12.293 10 6.646 4.354a.5.5 0 010-.708z"/></svg>
- 通過<img>元素引用
- <img src="/assets/img/bootstrap.svg" alt="" width="32" height="32" title="Bootstrap">
- 使用 SVG sprite
- <svg class="bi" width="32" height="32" fill="currentColor">
- <use xlink:href="bootstrap-icons.svg#heart-fill"/>
- </svg>
- <svg class="bi" width="32" height="32" fill="currentColor">
- <use xlink:href="bootstrap-icons.svg#toggles"/>
- </svg>
- <svg class="bi" width="32" height="32" fill="currentColor">
- <use xlink:href="bootstrap-icons.svg#shop"/>
- </svg>
- 通過 CSS 引入
- .bi::before {
- display: inline-block;
- content: "";
- background-image: url("data:image/svg+xml,<svg viewBox='0 0 16 16' fill='%23333' xmlns='http://www.w3.org/2000/svg'><path fill-rule='evenodd' d='M8 9.5a1.5 1.5 0 1 0 0-3 1.5 1.5 0 0 0 0 3z' clip-rule='evenodd'/></svg>");
- background-repeat: no-repeat;
- background-size: 1rem 1rem;
- }