实例首页
自学教程
IT工具箱
源代码
下载代码
上下布局
点击运行 >
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title>css 垂直居中 实例 - 自学教程(runoops.com)</title> <style> .center { line-height: 200px; height: 200px; border: 3px solid green; text-align: center; } .center p { line-height: 1.5; display: inline-block; vertical-align: middle; } </style> </head> <body> <h2>居中</h2> <p>以下实例中,我们让 line-height 属性值和 height 属性值相等来设置 div 元素居中:</p> <div class="center"> <p>我是垂直居中的。</p> </div> </body> </html>
运行结果: