css3 上下左右居中子元素的方法
2017-06-19 00:00
375 查看
<!DOCTYPE html>
<html lang="en" style="height: 100%">
<head>
<meta charset="UTF-8">
<title>Document</title>
<style>
.center {
width: 100%;
height: 100%;
position: relative;
background: #B3B39D;
}
.vertical-center {
width: 50%;
height: 50%;
background: #95E6F7;
transform: translate(-50%, -50%);
position: absolute;
top: 50%;
left: 50%;
}
</style>
</head>
<body style="height: 100%">
<div class="center">
<div class="vertical-center">
</div>
</div>
</body>
</html>
<html lang="en" style="height: 100%">
<head>
<meta charset="UTF-8">
<title>Document</title>
<style>
.center {
width: 100%;
height: 100%;
position: relative;
background: #B3B39D;
}
.vertical-center {
width: 50%;
height: 50%;
background: #95E6F7;
transform: translate(-50%, -50%);
position: absolute;
top: 50%;
left: 50%;
}
</style>
</head>
<body style="height: 100%">
<div class="center">
<div class="vertical-center">
</div>
</div>
</body>
</html>
相关文章推荐
- 图片自适应父元素大小,并左右上下居中的css方法
- 图片自适应父元素大小,并左右上下居中的css方法
- 弹层高度宽度不确定,始终上下左右居中(css方法)
- CSS处理文本上下、左右居中的方法,以及最右边列自动适应
- css:子元素div 上下左右居中方法总结
- css---flex布局中,如何响应式 得水平垂直居中?flex子元素左右 上下居中
- css 宽高未知的子元素在父容器上下左右居中
- css:子元素div 上下左右居中方法总结
- css+div 上下左右居中两例
- 不用table,两种div+css页面元素居中方法
- 让图片img标签在div里上下左右居中的方法
- 一个上下左右都居中的非table的纯CSS实现代码
- 纯CSS实现上下左右都居中的代码
- CSS常见的让元素水平居中显示的方法
- css任意图片文字上下左右都居中对齐
- div+css:页面整体布局居中显示:上下居中||垂直居中,左右居中||水平居中
- 6种CSS控制元素上下居中效果
- CSS常见的让元素水平居中显示方法
- css图片自动绽放大小,左右,上下居中
- CSS小技巧网页居中报表页面左右抖动解决方法