vue---museui解决底部/顶部导航栏位置固定问题
移动端页面通常会包括顶部导航或底部导航栏,导航栏一般固定在页面上。问题描述如下:导航栏未固定,顶部红色导航栏会随着页面下滚而消失,底部的蓝色导航栏会根据页面内容变化而上下浮动,视觉体验非常不好。解决方法:给导航栏添加css样式(1)底部蓝色导航栏,设置样式position:fixed; left:0; bottom:0;width: 100%;z-index: 1000;代...
·
移动端页面通常会包括顶部导航或底部导航栏,导航栏一般固定在页面上。
问题描述如下:
导航栏未固定,顶部红色导航栏会随着页面下滚而消失,底部的蓝色导航栏会根据页面内容变化而上下浮动,视觉体验非常不好。
解决方法:
给导航栏添加css样式
(1)底部蓝色导航栏,设置样式position:fixed; left:0; bottom:0;width: 100%;z-index: 1000;代码如下:
<template>
<!-- 底部导航栏 -->
<div id="nav">
<mu-bottom-nav style="background-color: #2196f3;color: hsla(0,0%,100%,.7);">
<router-link to="/student">
<mu-bottom-nav-item title="首页" icon="home"></mu-bottom-nav-item>
</router-link>
<router-link to="/studyResource">
<mu-bottom-nav-item title="学习资源" icon="local_library"></mu-bottom-nav-item>
</router-link>
<router-link to="/discuss">
<mu-bottom-nav-item title="讨论交流" icon="record_voice_over"></mu-bottom-nav-item>
</router-link>
<router-link to="/PersonalCenter">
<mu-bottom-nav-item title="个人中心" icon="account_circle"></mu-bottom-nav-item>
</router-link>
</mu-bottom-nav>
</div>
</template>
<script>
export default {
data() {
return {
// shift: "index"
};
}
};
</script>
<style lang="less">
.mu-bottom-item-active {
color: white;
}
a {
color: rgba(218, 214, 214, 0.7);
}
// 固定底部导航栏位置
#nav {
position: fixed;
width: 100%;
left: 0;
bottom: 0;
z-index: 1000;
}
</style>
(2)顶部红色导航栏,由于多个页面分别都包含不同名称(如:学习资源,课程知识地图等等)的顶部导航栏,为顶部导航栏添加相同class="header_title"
在App.vue中为它们设置统一样式position: fixed;width: 100%;left: 0;top: 0;z-index: 1000;
<template>
<div id="app">
<router-view/>
<!-- bottom-nav 底部导航栏 -->
<bottom-nav v-show="showNav"></bottom-nav>
</div>
</template>
<script>
import BottomNav from "./components/BottomNav";
export default {
name: "App",
data() {
return {
showNav: false
};
},
components: {
"bottom-nav": BottomNav
}
};
</script>
<style>
#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;
}
.header_title {
position: fixed;
width: 100%;
left: 0;
top: 0;
z-index: 1000;
}
</style>
完美解决问题,导航栏固定住啦~~ 效果图展示如下:
更多推荐
已为社区贡献45条内容
所有评论(0)