vue中设置height:100%无效的问题及解决方法
时间:2021-03-08 11:35:22|栏目:vue|点击: 次
在vue.js中写新的components的时候,如果在新页面中的模板中设置height:100%的时候一直无效。
App.vue文件
<template>
<div id="app">
<router-view/>
</div>
</template>
<script>
export default {
name: 'App'
}
</script>
<style>
#app {
font-family: 'Avenir', Helvetica, Arial, sans-serif;
-webkit-font-smoothing: antialiased;
-moz-osx-font-smoothing: grayscale;
text-align: center;
color: #2c3e50;
}
</style>
这时候设置height: 100%;是无效的,在chrome的Elements中发现height仍然是0px.
设置高度100%时,div的高度会等同于其父元素的高度。而上面中id为app的div(vue挂载的div)的父节点是body标签,body标签的父节点是html标签。在默认情况下html和body标签的高度为auto,而浏览器是不会自动给标签添加高度的,所以html和body标签就为0,自然子div的高度设置为100%就不起作用了。
此时应该在App.vue文件style中添加如下代码:
html,body,#app{
height: 100%;
}
总结
上一篇:实现vuex原理的示例
栏 目:vue
下一篇:浅谈vue使用axios的回调函数中this不指向vue实例,为undefined
本文标题:vue中设置height:100%无效的问题及解决方法
本文地址:http://www.codeinn.net/misctech/76322.html






