• css常用居中


    对一个已知大小的元素上下左右居中(已知大小了,直接margin也就行了):

    css如下:
    .parent{height:100px;100px;background:grey;position:relative;}
    .Absolute-Center {
    height:50px;
    50px;
    margin: auto;
    position: absolute;
    top: 0; left: 0; bottom: 0; right: 0;
    background:red;
    }
    html如下:
    <div class="parent">
    <div class="Absolute-Center">
    </div>
    </div>

    未知高度上下左右居中

    css如下:
    .parent{height:200px;200px;background:green;position:relative;}
    .absolutecentercontent { 
    margin:auto;
    position:absolute; 
    100px;
    display: table; 
    height: auto; 
    background:red;
    top:0px;
    left:0px;
    right:0px;
    bottom:0px;

    .test{
    height:50px;
    50px;
    background:white;
    }
    html如下
    <div class="parent">
    <div class="absolutecentercontent">
    <div class="test"><div>
    </div>
    </div>

    未知高度上下左右居中

    css如下:

    .parents{height:200px;200px;background:grey;position:relative;}

    • .is-Transformed {

    • 50%;

    • margin: auto; 

    • position: absolute; 

    • top: 50%; left: 50%; 

    • -webkit-transform: translate(-50%,-50%); 

    • -ms-transform: translate(-50%,-50%); 

    • transform: translate(-50%,-50%); 

    • background:red; 

    • }

    • html如下:

    <body>
    <div class="parents">
    <div class="is-Transformed">
    1212
    </div>
    </div>
    </body>

     css文字居中:

    .scatter{

    display:block;

    text-align: justify;

    text-justify:distribute-all-lines;/*ie6-8*/

    text-align-last:justify;/* ie9*/

    -moz-text-align-last:justify;/*ff*/

    -webkit-text-align-last:justify;/*chrome 20+*/

    }

    @media screen and (-webkit-min-device-pixel-ratio:0){/* chrome*/

    .scatter:after{

    content:".";

    display: inline-block;

    100%;

    overflow:hidden;

    height:0;

    }

    }

    在不确定文字是否一行能显示完时,对文字的上下居中应该是设置padding,行的高度不做设定,自适应,word-break:break-all;换行显示;

    学而不思则罔,思而不结则殆,结而不看,一事无成
  • 相关阅读:
    (转)3D模板阴影原理
    (转)c++模版:包含模型、显式实例化、分离模型
    (转)C++内存管理
    (转)Ogre 安装 配置 问题
    (转)详细解说hash_map
    (转)STL中map用法详解
    VB Format函数
    转 python内置正则表达式(re)模块官方文档简要中文版
    《编程的奥秘》读后感
    python基础(5)正则表达式
  • 原文地址:https://www.cnblogs.com/windseek/p/6292258.html
Copyright © 2020-2023  润新知