无法将材质图标放置在垂直中心

时间:2018-08-23 11:34:32

标签: css google-material-icons

我试图将material icon放置在圆心中,因此尝试了以下方法 尝试添加vertical-align:middle并添加了text-align:center

但没有任何作用。

@font-face {
  font-family: 'Material Icons';
  font-style: normal;
  font-weight: 400;
  src: url(https://fonts.gstatic.com/s/materialicons/v41/flUhRq6tzZclQEJ-Vdg-IuiaDsNc.woff2) format('woff2');
}

.mi {
  font-family: 'Material Icons';
  font-weight: normal;
  font-style: normal;
  line-height: 1;
  letter-spacing: normal;
  text-transform: none;
  display: inline-block;
  white-space: nowrap;
  word-wrap: normal;
  direction: ltr;
  -webkit-font-feature-settings: 'liga';
  -webkit-font-smoothing: antialiased;
}

a {
  border: 1px solid #3D3E02;
  border-radius: 50%;
  padding: 10px;
  color: #334048;
}

a i {
  font-size: 20px;
}
.t{vertical-align:middle}
<link href="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/3.3.7/css/bootstrap.css" rel="stylesheet" />
<br><br><br>
<a href="#"><i class="mi">&#xe0be;</i></a>
<br><br><br>
<a href="#"><i class="mi t">&#xe0be;</i></a>

3 个答案:

答案 0 :(得分:1)

我将.t{vertical-align:middle}更改为.t{vertical-align:bottom},对我来说效果很好。

@font-face {
  font-family: 'Material Icons';
  font-style: normal;
  font-weight: 400;
  src: url(https://fonts.gstatic.com/s/materialicons/v41/flUhRq6tzZclQEJ-Vdg-IuiaDsNc.woff2) format('woff2');
}

.mi {
  font-family: 'Material Icons';
  font-weight: normal;
  font-style: normal;
  line-height: 1;
  letter-spacing: normal;
  text-transform: none;
  display: inline-block;
  white-space: nowrap;
  word-wrap: normal;
  direction: ltr;
  -webkit-font-feature-settings: 'liga';
  -webkit-font-smoothing: antialiased;
}

a {
  border: 1px solid #3D3E02;
  border-radius: 50%;
  padding: 10px;
  color: #334048;
}

a i {
  font-size: 20px;
}
.t{vertical-align:bottom}
<link href="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/3.3.7/css/bootstrap.css" rel="stylesheet" />
<br><br><br>
<a href="#"><i class="mi">&#xe0be;</i></a>
<br><br><br>
<a href="#"><i class="mi t">&#xe0be;</i></a>

这是您要找的吗?希望这能解决您的问题。

答案 1 :(得分:0)

使用display: inline-flex;a

@font-face {
  font-family: 'Material Icons';
  font-style: normal;
  font-weight: 400;
  src: url(https://fonts.gstatic.com/s/materialicons/v41/flUhRq6tzZclQEJ-Vdg-IuiaDsNc.woff2) format('woff2');
}

.mi {
  font-family: 'Material Icons';
  font-weight: normal;
  font-style: normal;
  line-height: 1;
  letter-spacing: normal;
  text-transform: none;
  display: inline-block;
  white-space: nowrap;
  word-wrap: normal;
  direction: ltr;
  -webkit-font-feature-settings: 'liga';
  -webkit-font-smoothing: antialiased;
}

a {
  display: inline-flex;
  border: 1px solid #3D3E02;
  border-radius: 50%;
  padding: 10px;
  color: #334048;
}

a i {
  font-size: 20px;
}
.t{vertical-align:middle}
<link href="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/3.3.7/css/bootstrap.css" rel="stylesheet" />
<br><br><br>
<a href="#"><i class="mi">&#xe0be;</i></a>
<br><br><br>
<a href="#"><i class="mi t">&#xe0be;</i></a>

答案 2 :(得分:0)

更改样式:

来自:

a {
  border: 1px solid #3D3E02;
  border-radius: 50%;
  padding: 10px;
  color: #334048;
}

a{
}

来自

a i {
    font-size: 20px;
}

a i {
    font-size: 20px;
    border: 1px solid #3D3E02;
    border-radius: 50%;
    padding: 10px;
}