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实现水平垂直居中------(特别注意,里边的固定还是不固定)的更多相关文章

  1. css3实现水平垂直居中

    1.transform实现居中(未设宽高) <div id="wrap">内容</div> <style> #wrap{ padding:50p ...

  2. css3种不知道宽高的情况下水平垂直居中的方法

    第一种:display:table-cell 组合使用display:table-cell和vertical-align.text-align,使父元素内的所有行内元素水平垂直居中(内部div设置di ...

  3. CSS3中flexbox如何实现水平垂直居中和三列等高布局

    最近这些天都在弥补css以及css3的基础知识,在打开网页的时候,发现了火狐默认首页上有这样一个东西.

  4. 用CSS/CSS3 实现水平居中和垂直居中,水平垂直居中的方式

    一.水平居中 (1)行内元素解决方案:父为块元素+text-align: center 只需要把行内元素包裹在一个属性display为block的父层元素中,并且把父层元素添加如下属性即可: 使用te ...

  5. 水平垂直居中div(css3)

    一.在需要居中的元素加上如下C3属性即可: <!doctype html><html lang="en"><head> <meta cha ...

  6. css3 flex 详解,可以实现div内容水平垂直居中

    先说一下flex一系列属性: 一.flex-direction: (元素排列方向) ※ flex-direction:row (横向从左到右排列==左对齐) ※ flex-direction:row- ...

  7. css3不定宽高水平垂直居中

    1 justify-content:center;//子元素水平居中 2 align-items:center;//子元素垂直居中 3 display:-webkit-flex; 在父级元素上面加上上 ...

  8. CSS3/CSS之居中解析(水平+垂直居中、水平居中,垂直居中)

    首先,我们来看下垂直居中: (1).如果是单行文本,则可以设置的line-height的数值,让其等于父级元素的高度! <!DOCTYPE html> <html lang=&quo ...

  9. css3水平垂直居中(不知道宽高同样适用)

    css水平垂直居中 第一种方法: 在父div里加: display: table-cell; vertical-align: middle; text-align: center; 内部div设置: ...

随机推荐

  1. redhat7.2下VNC没法显示图像

    1,Symptom /root/.vnc/HR-ECC-PRD-02:1.log内容有信息如下: VNCSconnST: Server default pixel fromat depth 24 (3 ...

  2. android studio中为gradle指定cmake版本

    Android Studio相当于是Intellij基础上写了一个AS插件,这个插件使用gradle作为构建系统,因此构建出现问题先考虑gradle的文档. gradle可以使用native buil ...

  3. 进程间通信之数据传输--FIFO

    One of the fundamental features that makes Linux and other Unices useful is the “pipe”. Pipes allow ...

  4. Centos7安装配置Nginx_笔记

    从Nginx官方网站下载稳定的主要分支版本.然后解压开来. 在Linux中需要使用编译工具编译安装Nginx. 首先安装“Development Tools”工具,包含了所有编译Nginx所需的依赖工 ...

  5. CodeCombat第一关:KITHGARD地牢之KITHGARD精通

    https://www.cnblogs.com/OctoptusLian/p/7397602.html https://www.jianshu.com/p/065581a84879 https://w ...

  6. Mysql【第一课】

  7. git免密

    免账号密码输入 git clone https://lichuanfa%40gitcloud.com.cn:lcf13870752164@git.c.citic/Citic-Data/bigdata_ ...

  8. ARTS-week5

    Algorithm 给定两个有序整数数组 nums1 和 nums2,将 nums2 合并到 nums1 中,使得 num1 成为一个有序数组.说明:初始化 nums1 和 nums2 的元素数量分别 ...

  9. Echo团队Alpha冲刺随笔 - 第八天

    项目冲刺情况 进展 程序基本完成,根据实际,添加完善新接口 问题 根据功能对接出现的问题继续进行改进 心得 放假了放松下 今日会议内容 黄少勇 今日进展 测试小程序,添加异常和错误操作的处理 存在问题 ...

  10. sql语句的面试题

    中科软的面试题:http://www.mayiwenku.com/p-5888480.html 中科软的面试题:https://blog.csdn.net/woolceo/article/detail ...