前端界面加载的时候,为防止界面抖动,可以用如下设置进行占位
.zhanwei{
overflow: hidden;
width:100%;
height: 0px;
padding-bottom: 25%;
}
padding-bottom: 25%;代表按宽高比4:1进行占位,这里的宽代表的是父元素的宽度,高代表的25%*父元素的宽度的值
应用实例:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Document</title>
<!-- 1. 导入Vue的包 -->
<script src="./lib/vue-2.4.0.js"></script>
<style>
.wapper {
width: 600px;
height: 600px;
background: pink;
}
.wapper>div{
overflow: hidden;
height: 0px;
padding-bottom: 25%;
background: yellow;
margin-bottom: 10px;
}
.one {
width: 100%;
}
.two {
width: 50%;
}
.three {
width: 200px;
}
</style>
</head>
<body>
<div id="app">
<div class="wapper">
<div class="one"> 这是第1个,宽高600 X 125 </div>
<div class="two"> 这是第2个,宽高300 X 125 </div>
<div class="three"> 这是第3个,宽高200 X 125 </div>
</div>
<div>高相对于父元素而言,一直都是600 X 25% = 125</div>
</div>
<script>
var vm = new Vue({
el: '#app',
data: {
}
})
</script>
</body>
</html>
效果图: