css3实现水平垂直居中------(特别注意,里边的固定还是不固定)
a,----定位方式(父元素宽高固定,子元素宽高固定)
<div class="Father">
<div class="children"></div>
</div>
<style lang="scss" scoped>
.Father{
position: relative;
}
.children{
width: 50px;
height: 50px;
position: absolute;
top: 0px;
bottom: 0px;
left: 0px;
right: 0px;
margin: auto;
}
</style>
b, ----flex布局方式(父元素宽高不固定,子元素宽高不固定)
<div class="Father">
<div class="children"></div>
</div>
<style lang="scss" scoped>
.Father {
border: 1px solid red;
height: 100px;
display: flex;
justify-content: center;
align-items: center;
}
.children {
width: 50px;
height: 50px;
border: 1px solid blue;
}
</style>
c, ----transform方式(父元素宽高不固定,子元素宽高不固定)
<div class="Father">
<div class="children"></div>
</div>
<style lang="scss" scoped>
.Father {
border: 1px solid red;
height: 100px;
position: relative;
}
.children {
width: 50px;
height: 50px;
border: 1px solid blue;
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%); /* 使用css3的transform来实现 */
}
</style>
.
css3实现水平垂直居中------(特别注意,里边的固定还是不固定)的更多相关文章
- css3实现水平垂直居中
1.transform实现居中(未设宽高) <div id="wrap">内容</div> <style> #wrap{ padding:50p ...
- css3种不知道宽高的情况下水平垂直居中的方法
第一种:display:table-cell 组合使用display:table-cell和vertical-align.text-align,使父元素内的所有行内元素水平垂直居中(内部div设置di ...
- CSS3中flexbox如何实现水平垂直居中和三列等高布局
最近这些天都在弥补css以及css3的基础知识,在打开网页的时候,发现了火狐默认首页上有这样一个东西.
- 用CSS/CSS3 实现水平居中和垂直居中,水平垂直居中的方式
一.水平居中 (1)行内元素解决方案:父为块元素+text-align: center 只需要把行内元素包裹在一个属性display为block的父层元素中,并且把父层元素添加如下属性即可: 使用te ...
- 水平垂直居中div(css3)
一.在需要居中的元素加上如下C3属性即可: <!doctype html><html lang="en"><head> <meta cha ...
- css3 flex 详解,可以实现div内容水平垂直居中
先说一下flex一系列属性: 一.flex-direction: (元素排列方向) ※ flex-direction:row (横向从左到右排列==左对齐) ※ flex-direction:row- ...
- css3不定宽高水平垂直居中
1 justify-content:center;//子元素水平居中 2 align-items:center;//子元素垂直居中 3 display:-webkit-flex; 在父级元素上面加上上 ...
- CSS3/CSS之居中解析(水平+垂直居中、水平居中,垂直居中)
首先,我们来看下垂直居中: (1).如果是单行文本,则可以设置的line-height的数值,让其等于父级元素的高度! <!DOCTYPE html> <html lang=&quo ...
- css3水平垂直居中(不知道宽高同样适用)
css水平垂直居中 第一种方法: 在父div里加: display: table-cell; vertical-align: middle; text-align: center; 内部div设置: ...
随机推荐
- linux技能点七 shell
shell脚本:定义,连接符,输入输出流,消息重定向,命令的退出状态,申明变量,运算符,控制语句 定义:linux下的多命令操作文件 连接符: ::用于命令的分隔符,命令会从左往右依次执行 & ...
- mysql主从一致性校验工具-pt
一.环境 1.系统环境 系统 IP 主机名 说明 server_id centos6.7 MasterIP master 数据库:主 177 centos6.7 SlaveIP slave 数据库: ...
- docker启动报错解决及分析(Cannot create container for service *******: cannot mount volume over existing file, file exists /var/lib/docker/overlay2/)
现象: Cannot create container for service *******: cannot mount volume over existing file, file exists ...
- 安装nginx环境(含lua)时遇到报错ngx_http_lua_common.h:20:20: error: luajit.h: No such file or directory的解决
下面是安装nginx+lua环境时使用的相关模块及版本,ngx_devel_kit和lua-nginx-module模块用的都是github上最新的模块.并进行了LuaJIT的安装. #Install ...
- Codeforces I. Vessels(跳转标记)
题目描述: Vessels time limit per test 2 seconds memory limit per test 256 megabytes input standard input ...
- Codeforces G. Bus Number(dfs排列)
题目描述: Bus Number time limit per test 1 second memory limit per test 256 megabytes input standard inp ...
- Kotlin属性引用详解
继续来学习Kotlin反射相关的,这次主要是跟反射属性相关的东东. 属性引用(Property Reference): 属性引用的用法与函数(方法)引用的用法是完全一致,都是通过::形式来引用的.下面 ...
- Strength(HDU6563+2018年吉林站+双指针瞎搞)
题目链接 传送门 题意 你有\(n\)只怪,每只怪的伤害为\(a_i\),对手有\(m\)只怪,每只怪的伤害为\(b_i\),对手的怪有普通状态和防守状态(普通状态:如果你用攻击力为\(a_i(a_i ...
- Hadoop跨集群迁移数据(整理版)
1. 什么是DistCp DistCp(分布式拷贝)是用于大规模集群内部和集群之间拷贝的工具.它使用Map/Reduce实现文件分发,错误处理和恢复,以及报告生成.它把文件和目录的列表作为map任务的 ...
- 8-html表格
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <meta http ...