水平居中的几种方式
来源:互联网 发布:linux 开发工具 编辑:程序博客网 时间:2024/06/06 02:05
方式一:水平居中:给div设置一个宽度,然后添加margin:0 auto属性
div {
width: 200px;
height: 300px;
margin: 0 auto;
background-color: pink;
}
方式二:让绝对定位的div居中
div {
position: absolute;
width: 300px;
height: 300px;
margin: auto;
top: 0;
left: 0;
bottom: 0;
right: 0;
background-color: pink;
}
方式三:确定容器的宽高 宽500px 高 300px 的层
设置层的外边距
div {
position: absolute;
width: 500px;
height: 300px;
top: 50%;
left: 50%;
margin: -150px 0 0 -250px;
background-color: pink;
}
方式四:未知容器的宽高,利用 `transform` 属性
div {
position: absolute;
width: 500px;
height: 300px;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
background-color: pink;
}
以上经验和代码整理来至:https://github.com/markyun/My-blog/tree/master/Front-end-Developer-Questions/Questions-and-Answers
- 水平居中的几种方式
- 水平垂直居中的几种方式
- HTML几种设置水平居中和垂直居中的方式
- html里元素水平居中和垂直居中的几种方式
- CSS水平居中的几种方法
- 水平垂直居中的几种写法
- 水平垂直居中的几种写法
- 水平垂直居中的几种写法
- 水平垂直居中的几种写法
- 水平垂直居中的几种写法
- 水平垂直居中的几种方法
- 水平垂直居中的几种方法
- div盒子水平居中垂直居中的几种方法
- 常用的几种水平垂直居中方式(按受用几率来写)
- 用纯css使div水平居中的几种方式
- 垂直水平居中的方式
- css未知宽度水平居中的几种解决方案
- 用css实现垂直水平居中的几种方法
- jedis操作redis
- 13.JAVA基础:八进制,十六进制表示
- 【LeetCode】 462. Minimum Moves to Equal Array Elements II
- .cc和.cpp的区别
- linux ps指令学习使用简单方法
- 水平居中的几种方式
- 引入rxtx串口通信jar及native path的坑
- Unity开发HTC vive 一、手柄按钮
- C语言小数四舍五入输出可控制位数
- linux学习笔记--sysctl命令
- jquery 对 checkbox 的 全选、反选、全不选等操作
- 【Operator】ESPN在DirectTV 机顶盒上推出APP
- 基于GPU加速全同态加密文献综述
- 数据库批量导出数据,可以拿去直接使用,程序员来涨姿势啦(二)