垂直居中

简介: 方案一   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

开始做,坚持做,重复做
相关文章
|
1月前
|
前端开发
CSS水平居中与垂直居中的方法
CSS水平居中与垂直居中的方法
|
3天前
|
前端开发
css flex布局两个元素水平居中垂直居中
css flex布局两个元素水平居中垂直居中
15 1
|
10月前
垂直居中 #32
垂直居中 #32
29 0
|
前端开发
CSS的垂直居中和水平居中总结
CSS的垂直居中和水平居中总结
117 0
超级居中
超级居中
60 0
超级居中
|
前端开发
CSS水平居中+垂直居中+水平/垂直居中的方法总结
CSS水平居中+垂直居中+水平/垂直居中的方法总结
180 0
CSS水平居中+垂直居中+水平/垂直居中的方法总结
|
前端开发
盒子模型 边框border 外边距 内边距
盒子模型 边框border 外边距 内边距
216 0
盒子模型 边框border 外边距 内边距
|
移动开发 安全 weex
基于 Flex 实现两端对齐垂直布局
一般来说布局我们都是水平布局,最多搞个垂直居中。而且对于一些 float 、 position 好像本身就不太适合垂直布局。 正好前段时间用 weex 做了一个页面,weex 天生基于 flex 。且 weex 中 flex-direction 默认值为 column,flex-direction 定义了 flex 容器中 flex 成员项的排列方向。 页面分为三部分(header,section,footer),有一些优化的点: 类似两端对齐,但是最好可以让 section 偏上一点 尽可能一屏显示,如果不够那么出滚动条。 那么我们来看看有什么方案可以实现。
477 0
基于 Flex 实现两端对齐垂直布局
|
前端开发 开发者
Margin 居中 | 学习笔记
快速学习 Margin 居中。
947 0
|
前端开发
CSS布局之居中
CSS布局之居中本文主要是介绍水平居中,垂直居中,还有水平垂直居中的方法水平居中 1.行内元素水平居中 使用text-align:center;就可以实现行内元素的水平居中,但是记得要在父元素中设置,会对子元素生效。
1347 0