在浏览器的可视区域占比50%高度,内容高度自适应上下左右居中
比如占比50%的可视化高度:height: 50vh;
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>屏幕高度占比自适应</title>
</head>
<style type="text/css">
main {
display: block;
}
h1{
font-size: 2.441rem;
font-weight: 600;
}
.main-wrapper {
flex-direction: column;/*主轴的方向为从上到下*/
height: 50vh; /*视窗高度的百分比*/
margin-bottom: 2em;
}
.main-wrapper {
display: flex;/*弹性布局*/
align-items: center;/*定义项目在交叉轴上居中对齐*/
color: #fbfeff;
padding: 0.5em 1em;
background: #1a3ea2;
}
.header-content {
flex: 1;
display: flex;
text-align: center;
flex-direction: column;
justify-content: center;
}
</style>
<body>
<div>
<div class="main-wrapper">
<div class="header-content">
<h1>Find</h1>
</div>
</div>
<div class="" style="height: 800px;border: #333333 solid 1px;">
</div>
</div>
</body>
</html>
这样就可以保证类似的首页背景图内容,占比50%,内容居中,如搜索框等。
结果: