在vue.js中写新的components的时候,若是在新页面中的模板中设置height:100%的时候一直无效。html
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%就不起做用了。vue
此时应该在App.vue文件style中添加以下代码:
html,body,#app{ height: 100%; }