gpt4 book ai didi

css - 将 Material 图标与文本对齐

转载 作者:太空宇宙 更新时间:2023-11-03 21:09:16 25 4
gpt4 key购买 nike

我在下面的代码中使用了 Material 图标,但该图标的某些样式使图标与文本不对齐。你知道如何将图标与文字对齐吗?

https://jsfiddle.net/u127zxak/1/

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

.material-icons {
font-family: 'Material Icons';
font-weight: normal;
font-style: normal;
font-size: 24px;
line-height: 1;
letter-spacing: normal;
text-transform: none;
display: inline;
white-space: nowrap;
word-wrap: normal;
direction: ltr;
-webkit-font-feature-settings: 'liga';
-webkit-font-smoothing: antialiased;
background-color: red;
display: inline;
}

.alert {
position: relative;
padding: 0.75rem 1.25rem;
margin-bottom: 1rem;
border: 1px solid transparent;
border-radius: 0.25rem;
}

.alert-info {
color: #0c5460;
background-color: #d1ecf1;
border-color: #bee5eb;
}

.alert-info hr {
border-top-color: #abdde5;
}

.alert-info .alert-link {
color: #062c33;
}
<div class="alert alert-info" role="alert">
<span><i class="material-icons">face</i></span>

<span>
Test
</span>
</div>

最佳答案

设置图标<i>vertical-align: middle; .

我还会删除 <span>标签,它们实际上并没有做任何事情。

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

.material-icons {
vertical-align: middle; /* new */
font-family: 'Material Icons';
font-weight: normal;
font-style: normal;
font-size: 24px;
line-height: 1;
letter-spacing: normal;
text-transform: none;
display: inline;
white-space: nowrap;
word-wrap: normal;
direction: ltr;
-webkit-font-feature-settings: 'liga';
-webkit-font-smoothing: antialiased;
background-color: red;
display: inline;
}

.alert {
position: relative;
padding: 0.75rem 1.25rem;
margin-bottom: 1rem;
border: 1px solid transparent;
border-radius: 0.25rem;
}

.alert-info {
color: #0c5460;
background-color: #d1ecf1;
border-color: #bee5eb;
}
<div class="alert alert-info" role="alert">
<i class="material-icons">face</i> Test
</div>

关于css - 将 Material 图标与文本对齐,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48715738/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com