html - 如何将图标图像完美居中
问题描述
我有一个图标 img 并试图将其置于卡片 div 中,但不知何故无法正常工作。我已经尝试过text-align: center;
,display:flex; justify-content: center;
但都没有帮助。我在下面附上了我的代码。任何帮助表示赞赏。提前致谢。
* {
box-sizing: border-box;
}
.card {
background-color: #fff;
border-radius: 4px;
max-width: 0px;
height: 0px;
position: absolute;
padding: 20px;
color: #444;
cursor: pointer;
top: 3%;
right: 0.5%;
}
.card:before {
content: '';
display: block;
position: absolute;
background-color: #ccc;
left: 20px;
right: 20px;
bottom: 0;
top: 50%;
z-index: -1;
box-shadow: 0 0 40px lighten(#000, 60%);
transition: box-shadow .2s ease-in-out;
}
.card.level-1:hover:before {
box-shadow: 0 0 80px lighten(#000, 60%);
}
.card level-1 img {
display: flex;
justify-content: center;
}
<div class="card level-1">
<img src="https://img.icons8.com/windows/32/000000/microphone--v2.png" />
</div>
解决方案
您应该像这样将 flex 放在图像的容器上:
.card {
display: flex;
justify-content: center;
align-items: center;
}
推荐阅读
- bash - 将 eGrep 转换为 Grep
- c++ - 如何从 CMake 创建 Visual Studio 2015 解决方案
- google-cloud-firestore - Firestore 批量写入 - 如何限制创建文档的数量?
- mysql - 如何避免使用 Laravel 在选择中重复数据?
- c# - 在 c# 中从 CSV 文件中读取两列
- html - 当屏幕从全屏过渡到小屏时,如何修复内容的 css/html?
- python - 调用 decisionBar() 时,它不会将图像blit到屏幕上
- python - Flask AttributeError:“LoginForm”对象没有属性“userEmail”
- typescript - 如何在 TypeScript 中安全地使用函数属性
- c++ - 是否可以使用旧版 C++ API(版本 1.1.2)连接到 MongoDB Atlas?