css - 使用变换转换的中心元素(具有 50px 边距)
问题描述
我有一个绝对定位的元素,边距为 50px,因此在设置左侧 50% 和变换转换 (-50%) 元素后,由于边距而不是中心。是否有水平选项中心元素并保持边距 50px 并转换平移 (-50%)
我有一个边距为 50px 的 @mixin theme-btn
.btn{
@include theme-btn();
&--uslugi{
position: absolute;
bottom: 10px;
left: 50%;
transform: translateX(-50%);
}
}
解决方案
将父 div 添加到您的 div,例如:
HTML
<div class="box">
<div class="box-in">
</div>
</div>
和 CSS
.box {
display: flex;
justify-content: center;
}
.box-in {
margin: 50px;
height: 100px;
width: 400px;
border: 1px solid green;
}
推荐阅读
- html - 输入字段下的 div
- excel - 遍历 Excel VBA 中的表
- c# - 切换统一事件系统目标
- jquery - 在 ios 设备上将屏幕旋转为横向时菜单项变大
- asynchronous - 使用 Jest/Enzyme 测试异步 mapDispatchToProps 操作会出错
- ibm-watson - Watson Studio 定制
- javascript - 插入字符以作为电话号码输入
- node.js - Three.js 与打字稿自动完成
- python - DataFrame中的几何平均值
- java - mvn clean install 对于我的 spring-cloud-contract 消费者测试来说是成功的,但是当我手动运行测试时它们失败了?