HTML元素居中

news/2024/10/21 19:53:48/
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/news/1532768.html

相关文章

使用powershell的脚本报错:因为在此系统中禁止执行脚本

1.添加powershell功能环境&#xff1a; 2.启动powershell的执行策略 因为在此系统中禁止执行脚本。 set-executionpolicy unrestricted

如何在iPad上设置Chrome为默认浏览器

将Chrome设置为iPad上的默认浏览器&#xff0c;不仅能够享受到谷歌强大的搜索功能和丰富的扩展生态&#xff0c;还能通过一系列自定义设置来进一步提升浏览体验。本文将详细介绍如何在iPad上完成这一设置&#xff0c;并探讨如何通过优化Chrome浏览器的相关功能&#xff0c;让您…

【递归】8. leetcode 671 二叉树中第二小的节点

题目描述 题目链接&#xff1a;二叉树中第二小的节点 2 解答思路 注意这句话&#xff1a;该节点的值等于两个子节点中较小的一个 二叉树的根节点的值是整棵树中最小的值 本道题所要求的是二叉树中第二小的节点。因为根节点是最小的节点&#xff0c;那么我们只需要找到第一…

使用WebClient 快速发起请求(不使用WebClientUtils工具类)

使用WebClient发起网络请求_webclient工具类-CSDN博客文章浏览阅读717次&#xff0c;点赞9次&#xff0c;收藏8次。使用WebClient发起网络请求_webclient工具类https://blog.csdn.net/qq_43544074/article/details/137044825这个是使用工具类发起的&#xff0c;下面就不使用工具…

基于php摄影门户网站

作者&#xff1a;计算机学姐 开发技术&#xff1a;SpringBoot、SSM、Vue、MySQL、JSP、ElementUI、Python、小程序等&#xff0c;“文末源码”。 专栏推荐&#xff1a;前后端分离项目源码、SpringBoot项目源码、Vue项目源码、SSM项目源码 精品专栏&#xff1a;Java精选实战项目…

FastAPI挂载静态资源

FastAPI挂载静态资源 使用场景&#xff1a;前后端不分离&#xff0c;后端挂载图片&#xff0c;css,js等静态资源&#xff0c;给客户端响应html页面 首先假设项目根目录为app&#xff0c;app目录下的static为存放静态资源的目录 #app/main.py from fastapi import FastAPIapp…

微服务SpringGateway解析部署使用全流程

官网地址&#xff1a; Spring Cloud Gateway 目录 1、SpringGateway简介 1、什么是网关 2、为什么用网关【为了转发】 2、应用&#xff1a; 1.启动nacos 2.创建网关项目 3.网关配置1 4.网关配置2【了解】 5.过滤器配置【了解】 1、SpringGateway简介 核心功能有三个&…

bluefs _flush_range allocated: osd用空间但是显示ceph_bluefs_db_used_bytes is 100%

1、查看日志 tail -f /var/log/ceph/ceph-osd.2.log-6> 2024-05-23 09:29:20.734328 7f837d847d00 4 rocksdb: EVENT_LOG_v1 {"time_micros": 1716452960734313, "job": 1, "event": "recovery_started", "log_files"…