用CSS实现居中的几种方式
2017-06-01 18:06
169 查看
用CSS实现居中的几种方式
HTML
<div class="box"> <div class="content"></div> </div>
绝对定位居中(知道宽高)
<style> .box{ position:relative; width:500px; height:500px; } .content{ position:absolute; left:50%; right:50%; width:100px; height:100px; margin-left:-50px; margin-top:-50px; } </style>
flex布局实现
<style> .box{ display:flex; justify-content: center; align-items: center; width:500px; height:500px; background-color: red; } .content{ /*长度随意*/ width:100px; /*宽度随意*/ height:100px; background-color: #fff; } </style>
相关文章推荐
- 【笔试题】阿里内推---CSS实现元素居中的几种方式
- CSS实现垂直居中的几种方法
- css考核点整理(六)-水平居中定位的几种方式
- CSS 实现垂直居中的几种方案
- 纯CSS完美实现垂直水平居中的6种方式
- [分享] 纯CSS完美实现垂直水平居中的6种方式
- css 垂直居中的几种实现方法
- CSS实现垂直、水平居中方式
- 实现垂直居中的几种方式
- 用css实现垂直水平居中的几种方法
- 纯CSS完美实现垂直水平居中的6种方式
- 使用纯CSS实现未知尺寸的图片(但高宽都小于500px)在500px的正方形容器中水平和垂直居中。你有几种方法?
- 纯CSS实现垂直居中的几种方法
- 纯CSS完美实现垂直水平居中的6种方式
- CSS实现垂直居中的几种方法
- css实现水平、垂直居中的几种方法
- CSS实现居中的方式
- CSS实现垂直居中的几种方法
- [分享] 纯CSS完美实现垂直水平居中的6种方式
- 实现垂直居中的几种方式