css - 如何使 Bootstrap SVG 图标居中?
问题描述
我想使用没有引导程序的引导程序 SVG 图标。
https://icons.getbootstrap.com/icons/arrow-顺时针/
请参阅此代码:
<span>
<span style="vertical-align:middle;display:inline-block;">
<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" fill="currentColor" class="bi bi-arrow-clockwise" viewBox="0 0 24 24">
<path fill-rule="evenodd" d="M8 3a5 5 0 1 0 4.546 2.914.5.5 0 0 1 .908-.417A6 6 0 1 1 8 2v1z"/>
<path d="M8 4.466V.534a.25.25 0 0 1 .41-.192l2.36 1.966c.12.1.12.284 0 .384L8.41 4.658A.25.25 0 0 1 8 4.466z"/>
</svg>
</span>
<span style="vertical-align:middle;display:inline-block;">My Text 1</span>
</span>
<span>
<span style="vertical-align:middle;display:inline-block;">
<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="currentColor" class="bi bi-arrow-clockwise" viewBox="0 0 16 16">
<path fill-rule="evenodd" d="M8 3a5 5 0 1 0 4.546 2.914.5.5 0 0 1 .908-.417A6 6 0 1 1 8 2v1z"/>
<path d="M8 4.466V.534a.25.25 0 0 1 .41-.192l2.36 1.966c.12.1.12.284 0 .384L8.41 4.658A.25.25 0 0 1 8 4.466z"/>
</svg>
</span>
<span style="vertical-align:middle;display:inline-block;">My Text 2</span>
</span>
我的问题:如何将文本垂直对齐到它旁边的 SVG 图标的中心?
解决方案
我会为此使用 flexbox。就像是:
<span style="display: inline-flex; gap: 5px; align-items: center;">
<span style="display: flex; align-items: center; justify-content: center;">
<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="currentColor" class="bi bi-arrow-clockwise" viewBox="0 0 16 16">
<path fill-rule="evenodd" d="M8 3a5 5 0 1 0 4.546 2.914.5.5 0 0 1 .908-.417A6 6 0 1 1 8 2v1z"/>
<path d="M8 4.466V.534a.25.25 0 0 1 .41-.192l2.36 1.966c.12.1.12.284 0 .384L8.41 4.658A.25.25 0 0 1 8 4.466z"/>
</svg>
</span>
<span>My Text 2</span>
</span>
<span style="display: inline-flex; gap: 5px; align-items: center;">
<span style="display: flex; align-items: center; justify-content: center;">
<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="currentColor" class="bi bi-arrow-clockwise" viewBox="0 0 16 16">
<path fill-rule="evenodd" d="M8 3a5 5 0 1 0 4.546 2.914.5.5 0 0 1 .908-.417A6 6 0 1 1 8 2v1z"/>
<path d="M8 4.466V.534a.25.25 0 0 1 .41-.192l2.36 1.966c.12.1.12.284 0 .384L8.41 4.658A.25.25 0 0 1 8 4.466z"/>
</svg>
</span>
<span>My Text 2</span>
</span>
推荐阅读
- python-3.x - Telethon Python 频道声明
- javascript - Javascript如何防止将HTML元素添加到DOM?
- c++ - 此语句 std::__throw_out_of_range(__N("array::at")) 中的 __N() 是什么?
- typescript - 从鉴别器也是联合的联合类型中提取
- java - Android 中的回收视图和查看器适配器的错误
- html - 如何使网站适合屏幕宽度?
- c++ - 没有重载函数 AddSnapshotListener 的实例与参数列表匹配
- javascript - 数组排序和值同时变化
- excel - 根据下拉列表选择更改双向单元格的目标
- javascript - 反应原生组件异常元素类型无效