css实现div垂直水平居中
来源:互联网 发布:李洪成排盘软件下载 编辑:程序博客网 时间:2024/05/22 09:41
方法一:display:table-cell 实现
<div class="wrapper"><div class="content">content</div></div>div居中:对父元素用display: table-cell; 子元素用display: inline-block;
文字居中:将line-height设为容器高度。
<style type="text/css">.wrapper{width: 300px;height: 200px;background: blue;display: table-cell;text-align: center;vertical-align: middle;}.content{width: 150px;height: 80px;line-height: 80px;background: red;display: inline-block;}</style>
方法二:position: absolute 实现
<style type="text/css">.wrapper{width: 300px;height: 200px;background: blue;position: relative;}.content{width: 150px;height: 80px;line-height: 80px;background: red;text-align: center;position: absolute;margin: auto;top: 0;left: 0;bottom: 0;right: 0;}</style>
方法三:弹性盒布局实现
可实现一个或多个内容块垂直水平居中
<div class="wrapper"><div class="content content1">content1</div><div class="content content2">content2</div><div class="content content3">content3</div></div>
按列分布的多个div的垂直水平居中
<style type="text/css">.wrapper{width: 300px;height: 200px;background: blue;display: flex;flex-direction:column;justify-content:center;align-items:center;}.content{width: 150px;height: 20px;line-height: 20px;background: red;text-align: center;margin: 5px;}</style>
按行分布的多个div的垂直水平居中
<style type="text/css">.wrapper{width: 300px;height: 200px;background: blue;display: flex;flex-direction:row;justify-content:center;align-items:center;}.content{width: 20px;height: 150px;line-height: 20px;background: red;text-align: center;writing-mode: tb-rl;margin: 5px;}</style>
阅读全文
0 0
- css实现div水平、垂直居中
- css div垂直水平居中实现
- css实现div垂直水平居中
- css实现div垂直水平居中
- css div水平垂直居中
- css(div水平垂直居中)
- CSS实现DIV水平居中和上下垂直居中
- div+css垂直居中和水平居中
- 【DIV+CSS】DIV背景图片水平垂直居中
- CSS:实现某个div在网页中垂直水平居中
- css实现div内图片的垂直、水平居中
- 3行Css实现div水平、垂直居中
- css实现div的水平和垂直居中
- css实现div的水平垂直居中方法
- CSS实现垂直水平居中
- CSS实现垂直 水平居中
- CSS实现垂直水平居中
- css实现垂直水平居中
- PHP 选猴王面试题
- 啦啦
- 【POJ1780】Code(欧拉回路)
- FPGA实现BT.1120编码
- 卸载kaldi并重新安装
- css实现div垂直水平居中
- Java垃圾回收机制(1)- GC的工作原理
- POJ3126 Prime Path —— BFS + 素数表
- Accelerated 13 Using inheritance and dynamic binding
- int x/*test*/y;的结果是?
- 自定义标题栏
- html旋转动画
- App瘦身
- response对象的使用