垂直居中

简介: 方案一   table-cell vertical-align DOCTYPE html> 垂直居中 table-cell vertical-align .

方案一   table-cell vertical-align

<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>垂直居中 table-cell vertical-align</title> 
    <link rel="stylesheet" type="text/css" href="../../reset.css">
    <style type="text/css">
    .parent{
        background: #bebebe;
        width: 50px;
        height: 200px;
        


      元格 */
        * 子元素垂直居中 */
    }
    .child{
        background: #404040;
        color:white;
        width: 50px;
        height: 50px;
    }
    </style>
</head>
<body>
<div class="parent">
    <div class="child">DEMO</div>
</div>
</body>
</html>

image

 

 

方案二   垂直居中absolute_transform

<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>垂直居中absolute_transform</title>
    <style type="text/css">
    .parent{
        background: #404040;
        height: 300px;
        width: 50px;

        position: relative;
    }
    .child{
        background: #bebebe;
        height: 50px;
        width: 50px;

       


    }
    </style>
</head>
<body>
<div class="parent">
    <div class="child">DEMO</div>
</div>
</body>
</html>

image

 

 

方案三 垂直居中flex_align-items

<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>垂直居中flex_align-items</title>
    <style type="text/css">
    .parent{
        background: #bebebe;
        height: 300px;
        width: 50px;

       
;/* 只设置display:flex时, align-items默认为 stretch 即拉伸,*/

    }
    .child{
        background: #404040;
        /*height: 50px;*/
        width: 50px;
        color: white;
    }
    </style>
</head>
<body>

<div class="parent">
    <div class="child">DEMO</div>
</div>

</body>
</html>

image

开始做,坚持做,重复做
相关文章
|
2月前
|
前端开发
CSS水平居中与垂直居中的方法
CSS水平居中与垂直居中的方法
|
11天前
|
前端开发
css flex布局两个元素水平居中垂直居中
css flex布局两个元素水平居中垂直居中
17 1
|
11月前
垂直居中 #32
垂直居中 #32
29 0
|
前端开发
CSS的垂直居中和水平居中总结
CSS的垂直居中和水平居中总结
117 0
超级居中
超级居中
60 0
超级居中
|
前端开发
CSS水平居中+垂直居中+水平/垂直居中的方法总结
CSS水平居中+垂直居中+水平/垂直居中的方法总结
182 0
CSS水平居中+垂直居中+水平/垂直居中的方法总结
|
前端开发
盒子模型 边框border 外边距 内边距
盒子模型 边框border 外边距 内边距
217 0
盒子模型 边框border 外边距 内边距
宽高不定实现盒子水平垂直居中
宽高不定实现盒子水平垂直居中
114 0
宽高不定实现盒子水平垂直居中
已知宽高实现盒子水平垂直居中
已知宽高实现盒子水平垂直居中
103 0
已知宽高实现盒子水平垂直居中