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

块、行内块水平垂直居中

1.定位实现水平垂直居中

<div class="outer"><div class="test inner1">定位实现水平垂直居中</div></div><style>.outer {width: 300px;height: 300px;border: 1px solid gray;margin: 100px auto 0;position: relative;}.test {width: 100px;height: 100px;background-color: orange;}.inner1 {/* 方法一 定位*/position: absolute;/* 相对于包含块,最近的定位的祖先或父元素 */top: 50%; left: 50%;margin-left: -50px;margin-top: -50px;}
</style>

2.定位+位移

<div class="outer"><div class="test inner2">定位+位移</div></div>
<style>
.outer {width: 300px;height: 300px;border: 1px solid gray;margin: 100px auto 0;position: relative;}.test {width: 100px;height: 100px;background-color: orange;}.inner2 {position: absolute;top: 50%;left: 50%;/*方法二  translate中的百分比是相对自身,50% 相当于100*50% = 50*/transform: translate(-50%, -50%);}
</style>

3.相对于整个视口水平垂直居中

 <div class="view">相对于整个视口水平垂直居中</div><style>body {position: relative;}/* 方法三 */.view {width: 100px;height: 100px;background-image: linear-gradient(red, yellow, green);position: fixed;top: 0;left: 0;right: 0;bottom: 0;margin: auto;}</style>

4.遮挡层

<div class="item"></div>/* 遮挡层 */.item {background-image: repeating-linear-gradient(red 200px, yellow 500px, green 700px);opacity: 0.5;position: fixed;top: 0;left: 0;right: 0;bottom: 0; }

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

相关文章:

  • Mybatis引出的一系列问题-动态 SQL
  • Docker学习之构建Base Image
  • SFM(Structure from Motion)和NeRF(Neural Radiance Fields)
  • [Vue] Vue2和Vue3的生命周期函数
  • springboot集成分布式任务调度系统xxl-job(调度器和执行器)
  • 11_Vue3中的新的组件
  • 详解推送Git分支时发生的 cannot lock ref 错误
  • [国产MCU]-BL602开发实例-PWM
  • 【JMeter】 使用Synchronizing Timer设置请求集合点,实现绝对并发
  • 无法对watchdog.sys等系统文件删除,弯道修复,这里解决办法很简单
  • ClickHouse(九):Clickhouse表引擎 - Log系列表引擎
  • 3.1 计算机网络和网络设备
  • 值得中国人民大学与加拿大女王大学金融硕士中的金融人观看的五部电影
  • 【数据库】Redis可以替代Mysql吗
  • 5 指针与多维数组:多维数组在内存中的存储与指针的关系
  • Spring 创建 Bean 的三种方式
  • 软工导论知识框架(五)面向对象方法学
  • MyBatisPlus代码生成器
  • 文件传输软件常见问题解决办法大全
  • springboot工程测试临时数据修改技巧
  • Echarts 清空画布空白以及鼠标悬浮提示信息格式化问题
  • 数据结构入门:栈
  • 《UNUX环境高级编程》(14)高级I/O
  • 第5讲:如何构建类的方法
  • 【TypeScript】TS接口interface类型(三)
  • Python web实战之Django 的 RESTful API 设计详解
  • Python 程序设计入门(014)—— Python 的 Lambda 函数(匿名函数)
  • 【MySQL系列】表约束的学习
  • 低功耗LoRaWAN国产低功耗LoRa+RF射频前端芯片XD6500S
  • 【基础IO】文件系统 {磁盘的物理结构,存储结构,逻辑结构;CHS 和 LBA 寻址方式;磁盘分区和块组;文件inode;软硬链接}