bootstrap 按钮中的图标未垂直对齐
bootstrap icons are not vertically aligned in button
当我尝试将新的 bootstrap 图标添加到按钮时,图像似乎有些偏差:
我可以在底部添加边距,但这似乎是一个“变通办法”。如果我检查以下代码:https://icons.getbootstrap.com/icons/x-circle/ 他们也没有使用任何解决方法,但它看起来符合预期。
这是我添加按钮的方式:
<a href="#" type="button" class="btn btn-danger"><i class="bi bi-x-circle"></i> Cancel</a>
我发现的一个细微差别是,如果通过图标字体而不是 svg 获取图标,它会在图像顶部添加一些 space,我无法通过任何填充将其删除控件。
我按照“安装”说明逐步操作,其他组件按预期工作。超棒的字体也很有魅力。
有什么正确的想法吗?
编辑:感谢大家到目前为止的回复。我经历了所有这些:
@vishal:
<div style="text-align:center; width:100%;">
<a href="#" type="button" class="btn btn-danger"><i class="bi bi-x-circle"></i> Cancel</a>
</div>
生成一个如下所示的按钮:
@乔治:
<a href="#" type="button" class="d-flex justify-content-center align-items-center col-12 btn btn-danger"><i class="bi bi-x-circle pr-2"></i> Cancel</a>
这里我不得不将 col-1 扩展到 col-12。但它也产生了这个按钮:
@camaulay:
如果我使用 svg 并调整宽度和高度(都设置为 20)并将视框定位调整为“0 0 20 20”,结果实际上看起来如预期:
<svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" fill="currentColor" class="bi bi-x-circle" viewBox="0 0 20 20">
所以我可以将其标记为正确答案。不过我想知道为什么 <i>
-Tag 会导致这种奇怪的行为?
如果我将边框 class 添加到“图片”,那么人们会看到图像顶部有一些额外的 space:
<a href="#" type="button" class="btn btn-danger"><i class="bi bi-x-circle pr-2 border"></i> Cancel</a>
我觉得可以帮到你。
<a href="#" type="button" class="d-flex justify-content-center align-items-center col-1 btn btn-danger"><i class="bi bi-x-circle"></i>Cancel</a>
HTML
<div class="center">
<a href="#" type="button" class="btn btn-danger">
<i class="bi bi-x-circle"></i> Cancel
</a>
</div>
Css
.center {
text-align:center;
width:100%;
}
这是一个已知错误,请参阅 https://github.com/twbs/icons/issues/82。
抱歉打扰了。
实际上,在官方示例中,有一些额外的样式应用于 bi class。此 pull.
中引入了此修复程序
所以样式本身是类似这样的:
.bi {
vertical-align: -.125em;
width: 1em;
height: 1em;
}
下面第二个按钮可以看到效果:
.bi {
vertical-align: -.125em;
width: 1em;
height: 1em;
}
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.0.0-beta3/dist/css/bootstrap.min.css" rel="stylesheet" />
<button type="button" class="btn btn-primary">
<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="currentColor" class="bi-x-circle" viewBox="0 0 16 16">
<path d="M8 15A7 7 0 1 1 8 1a7 7 0 0 1 0 14zm0 1A8 8 0 1 0 8 0a8 8 0 0 0 0 16z"></path>
<path d="M4.646 4.646a.5.5 0 0 1 .708 0L8 7.293l2.646-2.647a.5.5 0 0 1 .708.708L8.707 8l2.647 2.646a.5.5 0 0 1-.708.708L8 8.707l-2.646 2.647a.5.5 0 0 1-.708-.708L7.293 8 4.646 5.354a.5.5 0 0 1 0-.708z"></path>
</svg>
Cancel
</button>
<button type="button" class="btn btn-primary">
<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="currentColor" class="bi bi-x-circle" viewBox="0 0 16 16">
<path d="M8 15A7 7 0 1 1 8 1a7 7 0 0 1 0 14zm0 1A8 8 0 1 0 8 0a8 8 0 0 0 0 16z"></path>
<path d="M4.646 4.646a.5.5 0 0 1 .708 0L8 7.293l2.646-2.647a.5.5 0 0 1 .708.708L8.707 8l2.647 2.646a.5.5 0 0 1-.708.708L8 8.707l-2.646 2.647a.5.5 0 0 1-.708-.708L7.293 8 4.646 5.354a.5.5 0 0 1 0-.708z"></path>
</svg>
Cancel
</button>
当我尝试将新的 bootstrap 图标添加到按钮时,图像似乎有些偏差:
我可以在底部添加边距,但这似乎是一个“变通办法”。如果我检查以下代码:https://icons.getbootstrap.com/icons/x-circle/ 他们也没有使用任何解决方法,但它看起来符合预期。
这是我添加按钮的方式:
<a href="#" type="button" class="btn btn-danger"><i class="bi bi-x-circle"></i> Cancel</a>
我发现的一个细微差别是,如果通过图标字体而不是 svg 获取图标,它会在图像顶部添加一些 space,我无法通过任何填充将其删除控件。
我按照“安装”说明逐步操作,其他组件按预期工作。超棒的字体也很有魅力。
有什么正确的想法吗?
编辑:感谢大家到目前为止的回复。我经历了所有这些:
@vishal:
<div style="text-align:center; width:100%;">
<a href="#" type="button" class="btn btn-danger"><i class="bi bi-x-circle"></i> Cancel</a>
</div>
生成一个如下所示的按钮:
@乔治:
<a href="#" type="button" class="d-flex justify-content-center align-items-center col-12 btn btn-danger"><i class="bi bi-x-circle pr-2"></i> Cancel</a>
这里我不得不将 col-1 扩展到 col-12。但它也产生了这个按钮:
@camaulay: 如果我使用 svg 并调整宽度和高度(都设置为 20)并将视框定位调整为“0 0 20 20”,结果实际上看起来如预期:
<svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" fill="currentColor" class="bi bi-x-circle" viewBox="0 0 20 20">
所以我可以将其标记为正确答案。不过我想知道为什么 <i>
-Tag 会导致这种奇怪的行为?
如果我将边框 class 添加到“图片”,那么人们会看到图像顶部有一些额外的 space:
<a href="#" type="button" class="btn btn-danger"><i class="bi bi-x-circle pr-2 border"></i> Cancel</a>
我觉得可以帮到你。
<a href="#" type="button" class="d-flex justify-content-center align-items-center col-1 btn btn-danger"><i class="bi bi-x-circle"></i>Cancel</a>
HTML
<div class="center">
<a href="#" type="button" class="btn btn-danger">
<i class="bi bi-x-circle"></i> Cancel
</a>
</div>
Css
.center {
text-align:center;
width:100%;
}
这是一个已知错误,请参阅 https://github.com/twbs/icons/issues/82。 抱歉打扰了。
实际上,在官方示例中,有一些额外的样式应用于 bi class。此 pull.
中引入了此修复程序所以样式本身是类似这样的:
.bi {
vertical-align: -.125em;
width: 1em;
height: 1em;
}
下面第二个按钮可以看到效果:
.bi {
vertical-align: -.125em;
width: 1em;
height: 1em;
}
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.0.0-beta3/dist/css/bootstrap.min.css" rel="stylesheet" />
<button type="button" class="btn btn-primary">
<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="currentColor" class="bi-x-circle" viewBox="0 0 16 16">
<path d="M8 15A7 7 0 1 1 8 1a7 7 0 0 1 0 14zm0 1A8 8 0 1 0 8 0a8 8 0 0 0 0 16z"></path>
<path d="M4.646 4.646a.5.5 0 0 1 .708 0L8 7.293l2.646-2.647a.5.5 0 0 1 .708.708L8.707 8l2.647 2.646a.5.5 0 0 1-.708.708L8 8.707l-2.646 2.647a.5.5 0 0 1-.708-.708L7.293 8 4.646 5.354a.5.5 0 0 1 0-.708z"></path>
</svg>
Cancel
</button>
<button type="button" class="btn btn-primary">
<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="currentColor" class="bi bi-x-circle" viewBox="0 0 16 16">
<path d="M8 15A7 7 0 1 1 8 1a7 7 0 0 1 0 14zm0 1A8 8 0 1 0 8 0a8 8 0 0 0 0 16z"></path>
<path d="M4.646 4.646a.5.5 0 0 1 .708 0L8 7.293l2.646-2.647a.5.5 0 0 1 .708.708L8.707 8l2.647 2.646a.5.5 0 0 1-.708.708L8 8.707l-2.646 2.647a.5.5 0 0 1-.708-.708L7.293 8 4.646 5.354a.5.5 0 0 1 0-.708z"></path>
</svg>
Cancel
</button>