垂直水平居中的方式
来源:互联网 发布:中国经济网数据库 编辑:程序博客网 时间:2024/05/22 06:38
垂直水平居中的方式
垂直水平居中的方式列举出了四种方式:
方式一:利用属性拉扯的方式
<style type="text/css"> body,html{ background-color: #000000; } #box{ width: 400px; height: 300px; background-color: #FFFFFF; position: absolute; left: 0px; right: 0px; top: 0px; bottom: 0px; margin: auto; }</style><body> <div id="box"></div></body>
方式二:利用百分比
#box{ width: 400px; height: 300px; background-color: #fff; position: absolute; left: 50%; margin-left: -200px; top: 50%; margin-top: -150px; }
方式三:利用伸缩盒子
<style type="text/css"> html,body{ height: 100%; } body{ display: flex; justify-content: center; align-items: center; } #box{ width: 400px; height: 300px; background-color: #ccc; } </style>
方式四:利用伪元素,可以理解为span
<style type="text/css"> html,body{ background-color: #000; height: 100%; text-align: center;/*水平居中*/ } body:after{ content: ''; height: 100%; display: inline-block; vertical-align: middle; } #box { vertical-align: middle;/*垂直居中*/ display: inline-block; background-color: #fff; width: 400px; height: 300px; } </style>
阅读全文
0 0
- 垂直水平居中的方式
- 水平垂直居中的几种方式
- 元素水平居中和垂直居中的方式
- css实现水平居中和垂直居中的常见方式
- 元素水平居中和垂直居中的方式总结
- css3flex方式水平,垂直居中
- CSS垂直水平居中方式大全(二)----水平垂直居中
- 不定宽高的水平垂直居中实现方式
- css让容器水平垂直居中的n种方式
- 纯CSS实现垂直水平居中的5种方式
- 各种各样的水平垂直居中
- 元素的水平垂直居中
- 定宽高的水平垂直居中
- 文本的水平垂直居中
- CSS水平和垂直居中方式
- CSS实现垂直、水平居中方式
- 元素各种水平垂直居中方式
- 水平居中与垂直居中的区别
- noteBook2.11-C#基础第十一天
- exynap--快速完成代码插入神器
- lombok注解
- JAVA发展史
- Java IM环信服务端集成之用户体系集成(二)
- 垂直水平居中的方式
- 不是生活不公,而是你心里在作祟
- source insight中的快捷键总结
- oracle11g创建用户和表空间以及导入.DMP文件
- Java 的发展史
- xwindow
- idea创建maven项目没有webapp目录
- xRecyclerView的刷新,加载更多,多条目
- 学习笔记第二天