1 关于css实现水平垂直居中的一些方法:

.css的定位:用margin,padding,position

position:absolute;   //绝对定位,一般父级元素采用relative来配合使用,如果父级没有定位,将把body标签作为父级定位来使用

用position和margin的方法来实现两个div盒子的水平垂直居中:

html:

<body>
<div class="parent">
<div class="children">这里是子盒子</div>
</div>
</body>

css:

 <style>
        .parent{
            background-color:aquamarine;
            width:300px;
            height:300px;
            position:relative;
        }
        .children{
            background-color:yellow;
            width:100px;
            height:100px;
            position:absolute;
            top: 0%;
            right: 0%;
            bottom:0%;
            left:0%;
            margin:auto;
        }
        /* .children{
            
            width:100px;
            height:100px;
            position:absolute;
            top:100px;
            left:100px;
        } */
    </style>
用flex布局实现:用justify-content和align-items来设置水平轴和垂直轴的定位

css:

<style>
.parent {
background-color: aquamarine;
width: 300px;
height: 300px;
display: flex;
/* 水平 */
justify-content: center;
/* 垂直 */
align-items: center;
} .children {
background-color: yellow;
width: 100px;
height: 100px;
}
/* .children{ width:100px;
height:100px;
position:absolute;
top:100px;
left:100px;
} */
</style>

  

效果:

.inline-height设置行高来实现垂直居中,text-align:center来设置水平居中
        .parent{
background-color:aquamarine;
width:300px;
height:300px;
text-align: center;
}
.children{
display:inline-block;
line-height:300px; }

line-height:inherit;  //规定从父元素那里继承line-height的值

margin:inherit;   //规定从父元素那里继承margin的值

2 关于css层叠z-index的记录

z-index:属性在position(非stastic)中有效,数值可正可负,数值越大,离屏幕越近,比较要看它显示的不同的级别

最新文章

  1. FineUI第三天----WebConfig的配置
  2. HDU 4315 Climbing the Hill (阶梯博弈转尼姆博弈)
  3. ExtJS4.2.1自定义主题(theme)样式详解
  4. ajax 如何实现页面跳转
  5. money 和 smallmoney
  6. ios 中如何应对UIScrollView快速滑动(暴力用户,暴力测试)
  7. angularjs中ng-switch的用法
  8. (搬运工)国内顺利使用Google的另类技巧
  9. apache和tomcat的区别
  10. Windows2008RT搭建VPN服务器
  11. 使用Java创建RESTful Web Service(转)
  12. js一些重点知识总结(二)
  13. hdu 2669 Romantic 扩展欧几里得
  14. [POI2007]洪水pow bfs
  15. Leetcode解题思路总结(Easy篇)
  16. Day14全局变量与局部变量
  17. A Sample Linker Script
  18. 已以用户 NT AUTHORITY\SYSTEM 的身份执行。 对象 名称 &#39;XXX&#39; 包含的前缀超出了最大限值。最多只能有 2 个。
  19. 操作MySQL
  20. Java的背景、影响及前景

热门文章

  1. 588 div2 C. Anadi and Domino
  2. Solidity 编程实例--Blind Auction 盲拍
  3. Java 添加、修改、读取、删除PPT备注
  4. A Deep Neural Network Approach To Speech Bandwidth Expansion
  5. 基于Linux的kfifo移植到STM32(支持os的互斥访问)
  6. python程序调用C/C++代码
  7. AVL平衡二叉查找树
  8. 【Java 基础】谈谈集合.List
  9. WCE-hash注入工具使用
  10. JedisCluster与keys/scan查找