在移動端使用fixed佈局存在相容性問題,因此使用absolute佈局來代替 效果演示 src/app.vue里打好框架 <template> <div id="app" class="g-container"> <div class="g-header-container"> 頭部導航 </div ...
在移動端使用fixed佈局存在相容性問題,因此使用absolute佈局來代替
效果演示
src/app.vue里打好框架
<template> <div id="app" class="g-container"> <div class="g-header-container"> 頭部導航 </div> <div class="g-view-container"> <div class="content"> 內容區域 </div> </div> <div class="g-footer-container"> 底部導航 </div> </div> </template> <script> export default { name: 'App', } </script> <style scoped> .g-container{ position: relative; width:100%; height:100%; max-width:640px; min-width:320px; margin:0 auto; overflow:hidden; } .g-header-container{ position:absolute; left:0; top:0; width:100%; z-index:999; height:64px; background:pink; } .g-view-container{ height:100%; padding-bottom:80px; background:lightblue; overflow:auto; } .content{ height:2000px; } .g-footer-container{ position:absolute; left:0; bottom:0; width:100%; box-shadow:0 0 10px 0 hsla(0,6%,58%,0.6); height:80px; z-index:999; background:lightgreen; } </style>
在main.js里引入首頁文件的樣式index.scss
// The Vue build version to load with the `import` command // (runtime-only or standalone) has been set in webpack.base.conf with an alias. import 'babel-polyfill' import fastclick from 'fastclick' import Vue from 'vue' import App from './App' import router from './router' //給預設主頁引入index.scss樣式文件 import 'assets/scss/index.scss'; Vue.config.productionTip = false //給body元素設置fastclick fastclick.attach(document.body); /* eslint-disable no-new */ new Vue({ el: '#app', router, components: { App }, template: '<App/>' })
assets/scss/index.scss
*{ margin:0; padding:0; } html,body{ // 必須設置,否則內容滾動效果無法實現 width:100%; height:100%; }