如何使用Bootstrap 4垂直对齐按钮内容

2 html css twitter-bootstrap bootstrap-4 google-material-icons

我在应用程序中使用bootstrap 4和材料图标。问题是当我同时具有文本和图标的按钮时。

.button-icon {
  vertical-align: middle;
}
Run Code Online (Sandbox Code Playgroud)
<button class="button-icon">
    <i class="material-icons">account_box</i>
    My Account
</button>
Run Code Online (Sandbox Code Playgroud)

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

我只是想使文本与图标对齐。感谢您的任何帮助。

dfe*_*enc 11

在这种情况下,一种方法是使用Flexbox实用程序.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">
Run Code Online (Sandbox Code Playgroud)