html - 使图标大于文本,但仍然垂直居中
问题描述
我正在寻找实现这张照片的按钮,但我不知道如何将图标与文本对齐?
当前代码:
.btn {
-webkit-border-radius: 4;
-moz-border-radius: 4;
border-radius: 4px;
font-family: 'Raleway', sans-serif;
font-weight: 300;
color: #ffffff;
font-size: 17px;
background: #72a031;
display: inline-block;
padding: 0px 30px 0px 25px;
text-decoration: none;
}
.btn:hover {
background: #61872c;
text-decoration: none;
}
<link rel="stylesheet" href="https://use.fontawesome.com/releases/v5.0.10/css/all.css" integrity="sha384-+d0P83n9kaQMCwj8F4RJB66tzIwOKmrdb46+porD/OvrJ+37WqIM7UoBtwHO6Nlg" crossorigin="anonymous">
<button class='btn'>
<i style="font-size: 1.73em; position: relative;" class="fab fa-steam-symbol"></i> Log in with Steam
</button>
我知道这很混乱,真的很晚了,我只想让这个简单的东西正常工作!
解决方案
您可以使用CSS 选择器简单地添加vertical-align: middle
到按钮内的所有元素/内容:.btn *
.btn {
-webkit-border-radius: 4;
-moz-border-radius: 4;
border-radius: 4px;
font-family: 'Raleway', sans-serif;
font-weight: 300;
color: #ffffff;
font-size: 17px;
background: #72a031;
display: inline-block;
padding: 0px 30px 0px 25px;
text-decoration: none;
}
.btn * {
vertical-align: middle;
}
.btn:hover {
background: #61872c;
text-decoration: none;
}
<link rel="stylesheet" href="https://use.fontawesome.com/releases/v5.0.10/css/all.css" integrity="sha384-+d0P83n9kaQMCwj8F4RJB66tzIwOKmrdb46+porD/OvrJ+37WqIM7UoBtwHO6Nlg" crossorigin="anonymous">
<button class='btn'>
<i style="font-size: 1.73em; position: relative;" class="fab fa-steam-symbol"></i> Log in with Steam
</button>
推荐阅读
- javascript - 我不能使用 Node.JS 调用在另一个函数中创建的函数
- reactjs - 如何等待来自嵌套请求的 React 评估值?
- asp.net-core - 只有在 AspNetUsers 上的“EmailConfirmed”字段为真(NETCORE 3.1)时,具有有效凭据的用户才能登录
- django - Django Rest Framework 中的自定义字段验证
- python - tolist的numpy数组非常慢
- php - CakePHP 4 JSON 列值查找或设置别名
- react-native - 在 React Native 应用程序中使用的 SignalR npm 包
- python - Python 代码在 Mac 终端中运行,但不在 Neovim 中
- android - Unity 排行榜在 Play 商店发布后无法使用
- javascript - 每当切换输入字段时,状态默认为未定义