html - 如何使用 bootstrap 4 垂直对齐按钮内容

标签 html css twitter-bootstrap bootstrap-4 google-material-icons

我在我的应用程序中使用 bootstrap 4 和 Material 图标。问题是当我有一个同时包含文本和图标的按钮时。

.button-icon {
  vertical-align: middle;
}
<button class="button-icon">
    <i class="material-icons">account_box</i>
    My Account
</button>

我试过更改图标的字体大小,但这会影响整个页面中其他图标的大小。

我只是想让文本与图标居中。感谢您的帮助。

最佳答案

一种方法是使用 Flexbox utility类,.d-flex .align-items-center 在这种情况下。

<button class="btn button-icon d-flex align-items-center">
    <i class="material-icons">account_box</i>
    My Account
</button>

<link href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css" rel="stylesheet"/>
<link href="https://fonts.googleapis.com/icon?family=Material+Icons" rel="stylesheet">

关于html - 如何使用 bootstrap 4 垂直对齐按钮内容,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48492915/

相关文章:

html - 制作一个表格,每行 4 个单元格,通过将第三个和第四个单元格移动到新行中来响应

javascript - Bootstrap 3 和 IE8 问题

ruby-on-rails-3 - 如何使我的 LESS 变量可用于 Rails 中的所有 CSS 文件?

html - 解决链接之间的间隙问题,而不必将代码放在一行中

html - Bootstrap CSS 对齐一个分区类

javascript - 使用 append() 不会替换以前的内容

javascript - 根据文件选择器选择更改 div 背景

html - 使用 CSS 在列之间放置间隙

css - Bootstrap 中的冗余列类

javascript - Bootstrap 的日期选择器(仅选择周并使其在 IE 中工作)