Bootstrap 開源了首套 SVG 圖標庫 Bootstrap Icons,其團隊表示這是有史以來第一次擁有自己的圖標庫,此圖標庫起初專門針對其從表單控件到導航等組件和文檔進行定制設計和構建,現在可以免費用于任何項目,無論此項目是否使用了 Bootstrap。
查看 Bootstrap Icons »https://icons.getbootstrap.com/
既然 Bootstrap Icons 是 SVG 圖標庫,因此它們可以快速、輕松地擴展,并且可以配合 CSS 的使用進行個性化定制。雖然它們是為 Bootstrap 設計的,但可以在任何項目中使用。不過要注意的是,它們現在尚處于 alpha 階段,未來可能會出現重大變化。
Bootstrap Icons 官網提供了檢索圖標種類的搜索框,用戶可根據需求使用關鍵字(英文)進行查找。
根據自己的設置,可以通過多種方式將 Bootstrap Icons 添加到項目:
-
將 SVG 復制粘貼為內嵌式的 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;
- }