html - 绝对 div 内的图标未居中
问题描述
我正在尝试构建一个可以显示在屏幕左下角的 div。下面是css。
- 图标未居中且
- 对于移动设备,div 显示在屏幕中央。
如何使图标居中以及如何为较小的设备收缩 div?
SCSS
.dot {
position: fixed;
right: 100px;
bottom: 100px;
width: 100px;
height: 100px;
background: #6fbd14;
border-radius: 50%;
text-align: center;
vertical-align: bottom;
a {
i {
font-size: 80px;
color: #cfcfcf;
position: absolute;
left: 50%;
top: 50%;
transform: translateY(-50%);
&:hover,
&:focus {
color: $main-color;
}
}
}
}
HTML
<div class="dot">
<a routerLink="/market/cs">
<i class="ri-add-line"></i>
</a>
</div>
解决方案
试试这个
对于锚元素
height:100%;
width:100%;
display:inline-flex;
justify-content:center;
align-items:center;
从i
position: absolute;
left: 50%;
top: 50%;
transform: translateY(-50%);
.dot {
position: fixed;
right: 100px;
bottom: 100px;
width: 100px;
height: 100px;
background: #6fbd14;
border-radius: 50%;
text-align: center;
vertical-align: bottom;
}
.dot a {
height: 100%;
width: 100%;
display: inline-flex;
justify-content: center;
align-items: center;
}
.dot a i {
font-size: 80px;
color: #cfcfcf;
}
.dot a i:hover, .dot a i:focus {
color: green;
}
<div class="dot">
<a routerLink="/market/cs">
<i class="icon">I</i>
</a>
</div>
<script src="https://code.iconify.design/1/1.0.7/iconify.min.js"></script>
推荐阅读
- prolog - Prolog:存在量化
- python - 为 GitLab 发布创建资产
- javascript - v8 对象中“快速”、“可内联”属性的数量限制是多少?
- flutter - 如何将依赖于另一个流的流映射到依赖于两个流的新模型?
- node.js - Gitlab-ci.yml 在尝试获取邮递员/纽曼报告时失败:纽曼:找不到“”记者
- python - Airflow 将任务 job_name 参数读取为文件夹
- django - Django ORM、Q 语句和自定义排序
- sublimetext3 - 在范围函数 [xy] 内使用 sublime text 3 highlight 时,如何防止在搜索选项卡时突出显示空格?
- angular - 重新加载页面是否会使整个 Angular 应用程序重新运行?
- h2o - 如何修复 TypeError:调用 H2O get_grid 函数时“float”对象不可迭代?