Vue.js 和 CSS 实现网站导航栏,包含简介、新闻中心和制度公告
这里是网站的主要内容区域
/* 导航栏样式 */
nav {
display: flex;
flex-direction: row;
justify-content: space-between;
align-items: center;
width: 100%;
height: 60px;
background-color: #333;
color: #fff;
font-size: 20px;
}
.logo {
width: 40%;
padding-left: 20px;
}
.logo img {
height: 40px;
}
.menu {
width: 60%;
}
ul {
list-style: none;
display: flex;
flex-direction: row;
justify-content: space-around;
align-items: center;
height: 100%;
}
li {
position: relative;
cursor: pointer;
}
.box {
position: absolute;
top: 100%;
left: 50%;
transform: translateX(-50%);
padding: 10px;
background-color: #fff;
border: 1px solid #ccc;
z-index: 1;
cursor: pointer;
display: none;
}
/* 当鼠标悬停在标题上时显示对应的盒子 */
li:hover .box {
display: block;
}
/* 内容区域样式 */
.content {
margin-top: 20px;
padding: 20px;
background-color: #f0f0f0;
text-align: center;
font-size: 24px;
}
new Vue({
el: '#app',
data: {
show: [false, false, false]
},
methods: {
showBox(index) {
this.show.splice(index, 1, true);
},
hideBox(index) {
this.show.splice(index, 1, false);
},
goPage(page) {
// 点击盒子中的内容跳转到对应页面的代码
}
}
});
以上是一个简单的示例,你可以根据自己的需求进行修改和扩展。
原文地址: https://www.cveoy.top/t/topic/lNlh 著作权归作者所有。请勿转载和采集!