css - iphone (Safari) 不将 FontAwesome 图标居中
问题描述
我有一个带有 FontAwesome 图标的简单按钮。
<!DOCTYPE HTML>
<html>
<head lang="en">
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0"/>
<link rel="stylesheet" href="https://use.fontawesome.com/releases/v5.5.0/css/all.css" integrity="sha384-B4dIYHKNBt8Bc12p+WXckhzcICo0wtJAoU8YZTY5qE0Id1GSseTk6S+L3BlXeVIU" crossorigin="anonymous">
<style>
.myButton {
width: 34px;
height: 34px;
border-radius: 4px;
border: 0;
color: #357CA5;
background-color: rgba(0, 0, 0, 0.08);
text-align:center;
/* if I comment out the following line, the arrow will be shown in the middle */
font-size: 1em;
}
.myButton:hover {
background: #357CA5;
color: #FFFFFF;
cursor: pointer;
box-shadow: 0 4px 6px -5px rgba(0, 0, 0, 0.6);
}
</style>
</head>
<body>
<button class="myButton">
<i class="fas fa-arrow-left" aria-hidden="true"></i>
</button>
</body>
</html>
在所有浏览器中,图标都会显示在中间,除了 Iphone 上的 Safari。图标在右侧。
其他浏览器https://i.stack.imgur.com/X2FXK.png
苹果浏览器:https ://i.stack.imgur.com/KFxq8.png
如果我删除该行
font-size: 1em;
图标显示在中间。你知道我做错了什么吗?
解决方案
将这些添加到按住按钮的 div 的行中解决了移动 Safari 中的问题:
display: flex;
justify-content: space-around;
因此,整个元素最终如下:
.message-btn {
display: flex;
justify-content: space-around;
margin-top: 0;
width: 35px;
height: 35px;
background-color: white;
border-radius: 5px;
border-width: 1px;
border-color: #a3c862;
color: #a3c862;
text-transform: uppercase;
text-align: center;
-webkit-transition: 0.1s all ease-in-out;
transition: all .1s ease-in-out;
font-size:18px;
}
推荐阅读
- c# - C# WebClient UploadValues 卡住了
- django - 查询集的 Django 分页
- c# - 如何修复 Resharper 命令行工具中不一致的命名?
- javascript - 如何在 DHTMLX 甘特图的资源视图中捕获点击事件?
- unity3d - Unity:尽管 Application.runInBackground 为 false,但应用程序仍在后台运行
- ios - 无法在 iPad 或 iPhone 上访问网络检查器
- html - 段落中的 CSS 按钮多行就像一个锚标签(IE11 也是)
- python - ValueError - 使用 tensorflow.keras.model.fit() 和 tensorflow.keras.metrics 时不兼容的形状(自身、其他)
- ansible - Ansible Tower 复制 .yml 配置文件时出现问题
- sql-server - 通过 keyvault 连接到 sql server