css - 带有 vue js 的 flexbox 不工作

标签 css vue.js flexbox

有人能告诉我这个简单的代码有什么问题吗?刚开始探索 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>

最佳答案

为了让它工作,使用标准的 HTML,它应该是这样的,其中 html/body/#appheight: 100%,然后设置 display: flex; flex-direction: column;#app

这样 wrapper 上的 flex: 1 0 auto 将正常工作并占用剩余的可用空间。

html, body, #app {
  height: 100%;
  margin: 0;
}

#app {
  font-family: 'Avenir', Helvetica, Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-align: center;
  color: #2c3e50;
  
  display: flex;
  flex-direction: column;
}
.wrapper {
  flex: 1 0 auto;
}
footer {
  background: #ccc;
  padding: 20px;
}
  <div id="app">
    <div class="wrapper">
      <p>THIS IS MY CONTENT</p>
    </div>
    <footer>
      This is the footer
    </footer>
  </div>

关于css - 带有 vue js 的 flexbox 不工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46015085/

相关文章:

css - Google 应用程序脚本、gmail 插件对齐操作中心和 TextInput 样式

jquery - 在图像上实现抓取/噪声效果

javascript - 在 Vuex store 中合并两个状态

vue.js - Vuetify - 自定义文本时如何将复选框包含到 v-select

html - 如何在 table/flex 中使用 100% 高度的图像?

javascript - 在我的找不同游戏中不止一轮(javascript)

html - Mozilla Firefox 浏览器不加载样式表

javascript - 通过 Vue.js 中的插槽范围将 Prop 传递给所有 child 的正确方法

css - Flexbox:网格中元素之间的空间

html - 段落的CSS flexbox问题