css几种水平垂直居中
2019-08-27 23:53
106 查看
版权声明:本文为博主原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。
本文链接:https://blog.csdn.net/sxzxiaofeng168/article/details/100110745
1. 使用flex布局
在父容器中设置
.container{ displayy: flex; justify-content: center; align-items: center }
2. 绝对定位
分为已知宽高和未知宽高两种情况
已知宽高都是100px,设置自身为绝对定位(absolute),top和left为50%,margin-left、margin-top为自身的一半,也就是50px .item { width: 100px; height: 100px; border: 1px solid red; position: absolute; top: 50%; left: 50%; margin-left: -50px; margin-top: -50px; }未知宽高
/*使用traansform*/ .item { border: 1px solid red; position: absolute; top: 50%; left: 50%; transform: translate(-50%,-50%)
相关文章推荐
- css垂直水平居中的几种常用方案
- css 水平居中垂直居中的几种方法
- 纯CSS设置元素垂直水平居中的几种方法
- css实现水平垂直居中的几种方法
- css的几种垂直水平居中方法
- 使用纯CSS实现未知尺寸的图片(但高宽都小于500px)在500px的正方形容器中水平和垂直居中。你有几种方法?
- html中div如何水平和垂直居中的几种css方法代码
- css:盒子垂直水平居中的几种方法
- CSS实现水平垂直居中的几种方式
- CSS水平垂直居中的几种方法
- CSS几种常用水平垂直居中的方法
- CSS-几种未知长宽的垂直水平居中方法
- css对不定宽高的盒子设置水平垂直居中的几种方法
- css水平垂直居中的几种方式
- CSS实现水平垂直居中的几种方法
- CSS水平垂直居中的几种方法
- HTML中CSS文本、子div、图片水平居中和垂直居中的几种方法
- css 图片垂直水平居中以及清除浮动方式(常用几种方式)
- CSS水平垂直居中的几种方法
- 【css】实现垂直水平居中的几种方法