码迷,mamicode.com
首页 > 其他好文 > 详细

div内容水平垂直居中的正确玩法

时间:2020-06-10 21:15:57      阅读:57      评论:0      收藏:0      [点我收藏+]

标签:html   detail   cap   containe   text   play   oct   doctype   文字   

<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8" />
    <title></title>
    <style>
        .container {
            text-align: center;
            height: 300px;
            border: 1px solid rebeccapurple;
        }
        .container:before
        {
            display: inline-block;
            vertical-align: middle;
            content: "";
            height: 100%;
        }
        .center {
            display: inline-block;
            vertical-align: middle;
        }
    </style>
</head>

<body>
<div class="container">
    <div class="center">
        <h1>这个是居中标题</h1>
        <p>这里是一些文字,文字</p>
    </div>
</div>
</body>
</html>

改自:http://www.mamicode.com/info-detail-1275208.html

 

div内容水平垂直居中的正确玩法

标签:html   detail   cap   containe   text   play   oct   doctype   文字   

原文地址:https://www.cnblogs.com/rovedog/p/13088685.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!