html - translateX占用的固定位置元素应该如何居中?
问题描述
我想要一个水平居中的 HTML 元素,例如:
.u-message {
position fixed
left 50%
//transform: translateX(-50%); //but css animate occupy translateX, so i cant's use transform attribute,
//margin-left: xxxpx; //and I dont't sure how long of the HTML element width,so I cant's use it too.
}
我能做些什么 ?
解决方案
尝试使用弹性盒子
.u-message {
display: flex;
align-items: center;
justify-content: center;
}
推荐阅读
- cmake - 在库依赖项中为多个目标定义编译定义
- c++ - 映射内的向量迭代器(字符串)
- java - libGdx 和 Gradle 的 Scala 实例化错误
- rust - 是否有将列表 B 添加到列表 A 的容器和方法,以便 B 是 A 的子集
- python - 使用类名在 Python 中设置描述符属性的值
- python - 同一句子中的重复文本
- uml - 如何将来自 Frame 的刺激添加到 WhiteStarUML 中对象的生命线?
- swift - 将 DateTime 从一个 TimeZone 转换为另一个 TimeZone - Swift
- javascript - 如何删除内联 Jqgrid 中的选定行?
- java - 将字符串转换为日期火花sql