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

CSS之水平垂直居中

如何实现一个div的水平垂直居中

   <div class="content-wrapper"><div class="content">content</div></div>

在这里插入图片描述

  1. flex布局
 .content-wrapper {width: 400px;height: 400px;background-color: lightskyblue;display: flex;justify-content: center;align-items: center;}
  1. transform
 .content-wrapper {width: 400px;height: 400px;background-color: lightskyblue;position: relative;}.content {position: absolute;left: 50%;top: 50%;transform: translateX(-50%) translateY(-50%);}
  1. 定位
 .content-wrapper {width: 400px;height: 400px;background-color: lightskyblue;position: relative;}.content {width: 60px;height: 20px;position: absolute;left: 170px;top: 190px;}
  1. 计算距离
 .content-wrapper {width: 400px;height: 400px;background-color: lightskyblue;padding-top: 190px;padding-left: 170px;box-sizing: border-box;}.content-wrapper .content {width: 60px;height: 20px;}
  1. display:table-cell
  .content-wrapper {width: 400px;height: 400px;background-color: lightskyblue;display: table-cell;vertical-align: middle;}.content-wrapper .content {width: 100%;height: 20px;text-align: center;}
  1. line-height
  .content-wrapper {width: 400px;height: 400px;background-color: lightskyblue;line-height: 400px;}.content-wrapper .content {width: 100%;height: 20px;text-align: center;}
  1. margin: auto
  .content-wrapper {width: 400px;height: 400px;background-color: lightskyblue;position: relative;}.content {width: 60px;height: 20px;margin: auto;position: absolute;left: 0;top: 0;right: 0;bottom: 0;}
http://www.lryc.cn/news/299297.html

相关文章:

  • 2.8日学习打卡----初学RabbitMQ(三)
  • Unity学习笔记(零基础到就业)|Chapter02:C#基础
  • 容器化的基础概念:不可变基础设施解释:将服务器视为乐高积木,而非橡皮泥。
  • 智胜未来,新时代IT技术人风口攻略-第二版(弃稿)
  • Git分支和迭代流程
  • 数据库管理-第150期 Oracle Vector DB AI-02(20240212)
  • MySQL双写机制
  • uniapp的配置和使用
  • 【ES】--Elasticsearch的分词器深度研究
  • 【Langchain Agent研究】SalesGPT项目介绍(三)
  • Java安全 URLDNS链分析
  • 【网站项目】026校园美食交流系统
  • 使用raw.gitmirror.com替换raw.githubusercontent.com以解决brew upgrade python@3.12慢的问题
  • 深度学习的进展
  • [高性能] - 缓存架构
  • django实现外键
  • 飞天使-k8s知识点14-kubernetes散装知识点3-Service与Ingress服务发现控制器
  • 任务调度
  • 深刻反思现代化进程:20世纪与21世纪的比较分析及东西方思想家的贡献
  • 【FTP讲解】
  • java面试题整理
  • 探索NLP中的N-grams:理解,应用与优化
  • JAVA-数组乱序
  • Stable Diffusion 模型下载:majicMIX reverie 麦橘梦幻
  • Java开发四则运算-使用递归和解释器模式
  • [NSSCTF]-Web:[SWPUCTF 2021 新生赛]easyrce解析
  • 5.深入理解箭头函数 - JS
  • 高效的工作学习方法
  • 【MySQL】-17 MySQL综合-3(MySQL创建数据库+MySQL查看数据库+MySQL修改数据库+MySQL删除数据库+MySQL选择数据库)
  • 【教学类-46-08】20240212立体鱼1.0