step1 水平划分组件为三层
<template>
<div>
<div class="upPart">
a
</div>
<div class="centerPart">
b
</div>
<div class="downPart">
c
</div>
</div>
</template>
<script>
export default {
name: 'HelloWorld',
}
</script>
<style scoped>
.upPart{
background-color:blanchedalmond;
}
.centerPart{
background-color: aqua;
}
.downPart{
background-color: blueviolet;
}
</style>
写了三个div会发现边缘还是有空白的,在index.html文件里加入如下代码即可解决
<style>
html,body{
margin: 0;
padding: 0;
}
</style>
效果如下
step2 使三个div铺满整个屏幕
<template>
<div class="mainPage">
<div class="upPart">
a
</div>
<div class="centerPart">
b
</div>
<div class="downPart">
c
</div>
</div>
</template>
<script>
export default {
name: 'HelloWorld',
}
</script>
<style scoped>
html,body{
height: 100%;
width: 100%;
}
.mainPage{
height: 100%;
width: 100%;
}
.upPart{
height: 30%;
background-color:blanchedalmond;
}
.centerPart{
height: 30%;
background-color: aqua;
}
.downPart{
height: 40%;
background-color: blueviolet;
}
</style>
App.vue添加
#app{
height: 100%;
width: 100%;
}
index.html添加
html,body{
margin: 0;
padding: 0;
width: 100%;
height: 100%;
}
效果如下
step3垂直划分组件为两层
<template>
<div class="mainPage">
<div class="upPart">
a
</div>
<div class="centerPart">
b
</div>
<div class="downPart">
<div class="downPartLeft">
c
</div>
<div class="downPartRight">
d
</div>
</div>
</div>
</template>
<script>
export default {
name: 'HelloWorld',
}
</script>
<style scoped>
html,body{
height: 100%;
width: 100%;
}
.mainPage{
height: 100%;
width: 100%;
}
.upPart{
height: 30%;
background-color:blanchedalmond;
}
.centerPart{
height: 30%;
background-color: aqua;
}
.downPart{
height: 40%;
background-color: blueviolet;
}
.downPartLeft{
width: 40%;
/* 高度设置为父组件downPart的高度 */
height: 40%;
position: absolute;
display: inline-block;
}
.downPartRight{
width: 60%;
height: 40%;
background-color: coral;
/* position设置为absolu可以进行left right top bottom等设置 */
position: absolute;
/* 重要 设置右边离屏幕右边距离为0 */
right: 0%;
display: inline-block;
}
</style>
源码地址:https://github.com/IcedOtaku/dashboard