当前位置: 首页 > news >正文

CSS水平垂直居中

1.利用定位 + margin:auto

2.flex布局

3.grid布局

一、利用position+margin:auto

<style>.outer {position: relative;  /*父亲相对定位*/width: 200px;height: 200px;background-color: red;}.inner {position: absolute;   /*儿子绝对定位*/top: 0;bottom: 0;left: 0;right: 0;margin:auto;   /*上下左右外边距为auto*/width: 100px;height: 100px;background-color: yellow;}</style><div class="outer"><div class="inner"></div>
</div>

 二、利用flex

<style>.outer {display: flex;    /*弹性布局*/justify-content: center;  /*水平居中*/align-items: center;  /*垂直居中*/width: 200px;height: 200px;background-color: red;}.inner {width: 100px;height: 100px;background-color: yellow;}</style><div class="outer"><div class="inner"></div>
</div>

三、gird布局

<style>.father {display: grid;align-items:center;justify-content: center;width: 200px;height: 200px;background: skyblue;}.son {width: 10px;height: 10px;border: 1px solid red}
</style><div class="father"><div class="son"></div>
</div>

http://www.lryc.cn/news/108703.html

相关文章:

  • Yolov8-pose关键点检测:模型部署篇 | yolov8-pose.onnx python推理
  • Linux中提示No such file or directory解决方法
  • Sklearn-使用SVC对iris数据集进行分类
  • 项目经理必读:领导风格对项目成功的关键影响
  • 行业追踪,2023-08-04
  • 双链表(带哨兵位头节点)
  • MySQL - LOAD DATA LOCAL INFILE将数据导入表中和 INTO OUTFILE (速度快)
  • String ,StringBulider ,StringBuffer
  • 阶段总结(linux基础)
  • HTTP(超文本传输协议)学习
  • 23年7月工作笔记整理(前端)
  • pytorch学习——正则化技术——权重衰减
  • iTOP-RK3588开发板Ubuntu 系统交叉编译 Qt 工程-命令行交叉编译
  • Java进阶——数据结构与算法之哈希表与树的入门小结(四)
  • DataFrame中按某字段分类并且取该分类随机数量的数据
  • 【c++】rand()随机函数的应用(一)——rand()函数详解和实例
  • iOS——Block回调
  • html学习6(xhtml)
  • UML-活动图
  • 跨境电商怎么做?Live Market教你创业及做大生意
  • Linux 4.19 和Linux 5.10 的区别
  • 学习单片机的秘诀:实践与坚持
  • Hum Brain Mapp:用于功能连接体指纹识别和认知状态解码的高精度机器学习技术
  • Ajax图书管理业务
  • 对于爬虫代码的优化,多个方向
  • ffmpeg推流卡顿修复
  • Java02-迭代器,数据结构,List,Set ,TreeSet集合,Collections工具类
  • 离散 Hopfield 神经网络的分类与matlab实现
  • opencv 30 -图像平滑处理01-均值滤波 cv2.blur()
  • 中小企业的数字化营销应该如何着手?数字化营销到底要怎么做?