设置高度自适应不同设备屏幕的高度

qq音乐的歌曲播放页面,页面的宽度和设备宽度是一致,这时候我们就用的flex布局,但是首先要设置html和body宽度都为100%,因为百分比布局是相对父级元素来说的,有以下html代码

<body>
	<div class="main">
		<header></header>
		<div class="content"></div>
		<footer></footer>
	</div> 
</body>

css

<style>
html,body{
	height:100%;
	
}

.main{
	height:100%;
	display:flex
}
header{
	height:100rem;
}
.content {
	flex:1;
}
footer{
	height: 100rem;
}
</style>


然而,如果使用vue开发,由于是单页开发,只有一个页面,无法在单个组件中通过css的方式设置html和body(如果在index.html设置html和body后其他页面也都变成了高度自适应的,但是通常我们其他页面是不需要这种布局的),这时候可以通过js设置html和body的高度

  mounted() {
    /*console.log(document.documentElement.clientHeight)*/
    
    document.documentElement.style.height='100%'
    document.body.style.height='100%'
    document.getElementById('app').style.height='100%'
  }
  
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值