HTML元素居中

embedded/2024/10/19 7:30:07/
htmledit_views">

⾏内元素⽔平垂直居中 设置⽗级标签。 ⽔平居中: text-align: center 垂直居中: line-height:盒⼦⾼度

⽔平垂直都居中

<!DOCTYPE html>
<html>
<head><style>.container {position: relative;width: 200px;height: 200px;border: 1px solid black;}.child {position: absolute;top: 50%;left: 50%;transform: translate(-50%, -50%);width: 100px;height: 100px;background-color: blue;}</style>
</head>
<body><div class="container"><div class="child"></div></div>
</body>
</html>

top: 50%;

left: 50%;

transform: translate(-50%, -50%);

这三个需要一起用实现居中

 绝对定位 + 四个方向 margin: auto

<!DOCTYPE html>
<html>
<head><style>.container {position: relative;width: 200px;height: 200px;border: 1px solid black;}.child {position: absolute;top: 0;left: 0;right: 0;bottom: 0;margin: auto;width: 100px;height: 100px;background-color: blue;}</style>
</head>
<body><div class="container"><div class="child"></div></div>
</body>
</html>

      top: 0;

      left: 0;

      right: 0;

      bottom: 0;

      margin: auto;这5个需要一起用

flex 布局

<!DOCTYPE html>
<html>
<head><style>.container {display: flex;justify-content: center;align-items: center;width: 200px;height: 200px;border: 1px solid black;}.child {width: 100px;height: 100px;background-color: blue;}</style>
</head>
<body><div class="container"><div class="child"></div></div>
</body>
</html>

      display: flex;

      justify-content: center;

      align-items: center;这三个需要一起用

table-cell

<!DOCTYPE html>
<html>
<head><style>.container {display: table-cell;text-align: center;vertical-align: middle;width: 200px;height: 200px;border: 1px solid black;}.child {width: 100px;height: 100px;background-color: blue;}</style>
</head>
<body><div class="container"><div class="child"></div></div>
</body>
</html>

      display: table-cell;

      text-align: center;

      vertical-align: middle;这三个需要一起用


http://www.ppmy.cn/embedded/120037.html

相关文章

SpringBoot集成阿里easyexcel(二)Excel监听以及常用工具类

EasyExcel中非常重要的AnalysisEventListener类使用&#xff0c;继承该类并重写invoke、doAfterAllAnalysed&#xff0c;必要时重写onException方法。 Listener 中方法的执行顺序 首先先执行 invokeHeadMap() 读取表头&#xff0c;每一行都读完后&#xff0c;执行 invoke()方法…

2024 Fortinet OT工业安全高峰论坛成功举办

9月10日&#xff0c;“2024年Fortinet OT工业安全高峰论坛”于广州圆满闭幕。盛会紧扣“工业安全新行动&#xff0c;智驭AI新时代”主题&#xff0c;汇聚全球OT领域精英、技术先锋及安全领域翘楚&#xff0c;共谋OT现代化浪潮下的安全新篇章。通过多维度视角、深层次对话、鲜活…

C++中string的使用

文章目录 string类对象的常见构造string类对象的容量操作size() / length()&#xff1a;返回字符串的长度&#xff08;字符数&#xff09;。capacity()&#xff1a;返回当前字符串分配的容量&#xff08;即在重新分配内存前可以保存的字符数&#xff09;。检查是否为空&#xf…

基本控制结构2

顺序结构 程序按照语句的书写次序顺序执行。 选择结构 判断选择结构又称条件分支结构&#xff0c;是一种基本的程序结构类型。 在程序设计中&#xff0c;当需要进行选择、判断和处理的时候&#xff0c;就要用到条件分支结构。 条件分支结构的语句一般包括if语句、if–else…

git clone或repo init 时报错:fatal: 协议错误:错误的行长度 xxx

执行repo init或git clone时报错:protocol error: bad line length 或协议错误:错误的行长度 系统版本:Ubuntu20.04 repo version v2.47 repo launcher version 2.45 git version 2.25.1 报错信息 fatal: 协议错误:错误的行长度 948 fatal: 远端意外挂断了 repo: err…

从0学习React(4)---更新组件状态setState

在上篇文章中&#xff0c;我们讲了React中的一些基础&#xff0c;包括组件的种类以及state的使用。上篇文章的结尾&#xff0c;我们讲到了如何更新组件的状态&#xff08;使用setState&#xff09;。但是我没有讲的很详细&#xff0c;这篇文章我们详细的讲一下React中如何更新组…

Qt Linguist手册-翻译员

翻译人员 Qt Linguist 是为 Qt 应用程序添加翻译的工具。一旦安装了 Qt&#xff0c;就可以像开发主机上的其他应用程序一样启动 Qt Linguist。 Qt Linguist 主窗口包含一个菜单栏和以下视图&#xff1a; 上下文 (F6) 用于从上下文列表中选择要翻译的字符串。字符串 (F7) 用于…

选择租用徐州服务器机柜的作用有哪些?

企业为了线上网络业务&#xff0c;通常都会选择租用服务器来确保网络的稳定性&#xff0c;企业选择服务器租用和托管业务后&#xff0c;同时也需要租用服务器机柜来进行放置所使用的服务器&#xff0c;对于机柜企业可以选择租用徐州机柜&#xff0c;下面就来聊一下选择租用徐州…