【发布时间】:2018-02-11 09:29:01
【问题描述】:
有人能告诉我这个简单的代码有什么问题吗?刚开始探索 flexbox。它在普通的 html 上运行良好,但是一旦我对其进行了 vuejs 编辑,页脚就会停留在屏幕顶部,就好像没有 flex css 一样。
谢谢。
<template>
<div id="app">
<div class="wrapper">
<p>THIS IS MY CONTENT</p>
</div>
<footer>
This is the footer
</footer>
</div>
</template>
<script>
export default {
name: 'app',
data () {
return {
msg: 'Welcome to Your Vue.js App'
}
}
}
</script>
<style lang="scss">
#app {
font-family: 'Avenir', Helvetica, Arial, sans-serif;
-webkit-font-smoothing: antialiased;
-moz-osx-font-smoothing: grayscale;
text-align: center;
color: #2c3e50;
margin-top: 60px;
/* added as per LGSon's suggestion */
height: 100%;
flex-grow: 1;
display: flex;
flex-direction: column;
}
html, body {
height: 100%;
margin: 0;
}
body {
display: flex;
flex-direction: column;
}
.wrapper {
flex: 1 0 auto;
}
footer {
background: #ccc;
padding: 20px;
}
</style>
【问题讨论】:
-
如果你也给
#app一个高度,height: 100%,它应该可以正常工作 -
感谢您的快速回复。我补充说,但仍然没有运气。 :(
-
如果你给
#appflex-grow: 1? -
还是一样。
-
还要注意,
body上的display: flex将仅适用于它的孩子,我假设是#app,如果是这样,#app需要flex-grow: 1; display: flex; flex-direction: column跨度>