博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
常用居中方法记录
阅读量:4549 次
发布时间:2019-06-08

本文共 790 字,大约阅读时间需要 2 分钟。

1.相对定位

(1)在父元素中使用text-align:center;

(2)使用margin:auto;

(3)通过设置left,top偏移量和负边距实现居中

   width:[width]; height:[height];

    position:absolute;

    left:50% top:50px;

    margin-left:-[width];

    margin-top:-[height];

(4)通过偏移和css位移实现(css3版)

  position: absolute; left: 50%; top: 50%;

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

 

(5)绝对定位通过设置四个偏移量和外边距自动实现居中(水平+垂直)

  width:[width]; height:[height];

  position: absolute;

  left: 0; top: 0; right: 0; bottom: 0;

  margin: auto;

(6)不定宽居中

  

/*清浮动*/.preant::after{    content:" ";    display:block;    height:0px;    clear:both;}/*不定宽居中*/.preant{    position:relative;    display: table;    margin: 0 auto;}.child{    width:X;    height:X;    float:left;}

  

转载于:https://www.cnblogs.com/pangys/p/5585752.html

你可能感兴趣的文章
hdu2035 二分快速幂
查看>>
BOM浏览器对象模型
查看>>
python实现排序奇数在前偶数在后
查看>>
hdu 3368 曾经下过的棋
查看>>
Linux Shell 删除三天前文件
查看>>
微信小程序 使用mpvue
查看>>
常用模块-02
查看>>
接口测试总结
查看>>
测试的基本概念
查看>>
【ZOJ】3209 Treasure Map
查看>>
ActiveMQ 消息队列服务
查看>>
《程序是给自己看的还是给别人看的》
查看>>
(12) PHP 随笔---Smarty模板引擎 单模板多缓存、局部不缓存 20--21
查看>>
【转】Math.Atan2 方法
查看>>
C++设计模式之工厂方法模式
查看>>
poj3984_bfs+回溯路径
查看>>
MyEclipse使用技巧
查看>>
[译]径向镜片反畸变滤波
查看>>
畅通工程-最小生成树+并查集
查看>>
top命令输出解释以及load average 详解及排查思路
查看>>