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

Html CSS 布局,位置处理 居中 对齐

Html CSS 布局,位置处理

1、居中布局

1、div 让内部div居中对齐

  • html
<div class="container"><div class="item">I am centered!</div>
</div>
  • style
      .container {border: 2px solid rgb(75, 70, 74);border-radius: .5em;height: 200px;display: flex;align-items: center;   /*调整y方向的位置 start 顶端对齐,center居中,end底端对齐*/justify-content: center;  /*调整x方向位置  left 左对齐  center居中   right右对齐*/}.item {border: 2px solid rgb(95, 97, 110);border-radius: .5em;padding: 20px;width: 10em;text-align: center;}

div全局居中对齐

  • html
  <div class="box"></div>
  • style
.box{width:100px;height:100px;background-color: cyan;position: absolute;top:50%;left: 50%;transform: translate(-50%,-50%);}

使用盒子模式让内部div居中

display: -webkit-box;-webkit-box-orient: horizontal;-webkit-box-pack: center;-webkit-box-align: center;display: -moz-box;-moz-box-orient: horizontal;-moz-box-pack: center;-moz-box-align: center;display: -o-box;-o-box-orient: horizontal;-o-box-pack: center;-o-box-align: center;display: -ms-box;-ms-box-orient: horizontal;-ms-box-pack: center;-ms-box-align: center;display: box;box-orient: horizontal;box-pack: center;box-align: center;

使用绝对定位让div居中

position: absolute;
top: 50%;
left: 50%;
-webkit-transform: translate(-50%, -50%);
-moz-transform: translate(-50%, -50%);
-ms-transform: translate(-50%, -50%);
-o-transform: translate(-50%, -50%);
transform: translate(-50%, -50%);
http://www.lryc.cn/news/449737.html

相关文章:

  • Spring MVC系统学习(二)——Spring MVC的核心类和注解
  • conda虚拟环境安装包、依赖同一管理
  • Unity网络开发记录(四):在unity中进一步封装客户端类
  • Linux内核中的UART驱动-详解Linux内核UART驱动:结构与功能分析
  • 威胁检测与防范:如何及时、准确对抗安全风险
  • 数据结构串的kmp相关(求next和nextval)
  • 创建游戏暂停菜单
  • seata服务端部署
  • 理解Python闭包概念
  • 51单片机的教室智能照明系统【proteus仿真+程序+报告+原理图+演示视频】
  • 一款资产进行快速存活验证工具
  • I/O中断处理过程
  • 关于PHP 匿名函数在处理数据结构中的应用
  • 安卓13默认使用大鼠标 与配置分析 andriod13默认使用大鼠标 与配置分析
  • AI学习指南深度学习篇-批标准化在深度学习中的应用
  • 了解网络的相关信息
  • Java | Leetcode Java题解之第447题回旋镖的数量
  • Docker实践与应用举例
  • 828华为云征文 | 智能监控新篇章,Prometheus如何在华为云Flexusx容器环境中大展身手
  • 基于单片机的可调式中文电子日历系统
  • 《C++设计新思维-泛型编程与设计模式之应用》阅读记录
  • vue访问组件的数据和方法
  • Redis: RDB与AOF的选择和容灾备份以及Redis数据持久化的优化方案
  • Goweb---Gorm操作数据库(二)
  • 鸿蒙HarmonyOS之封装Http请求工具类
  • java基础(4)类和对象
  • [Linux]:线程(二)
  • 【unity进阶知识3】封装一个事件管理系统
  • 服务器使用frp做内网穿透详细教程,请码住
  • 小程序视频编辑SDK解决方案,轻量化视频制作解决方案