<el-menu>中,<el-menu-item>分别有首页、仓库、安装与教程、客服帮助、我的。这些菜单实现水平居中,我的水平靠右
时间: 2024-01-27 10:06:22 浏览: 29
可以使用Flex布局来实现这个效果。首先将`<el-menu>`的`display`属性设置为`flex`,并将`<el-menu-item>`的`flex`属性设置为1,这样每个菜单项就会平均分配容器的宽度。然后将`<el-menu-item>`的文本居中,可以使用`text-align: center;`来实现。最后,将“我的”这个菜单项的`margin-left`属性设置为`auto`,这样它就会被推到最右侧。
具体代码如下:
```html
<el-menu class="menu" mode="horizontal">
<el-menu-item>首页</el-menu-item>
<el-menu-item>仓库</el-menu-item>
<el-menu-item>安装与教程</el-menu-item>
<el-menu-item>客服帮助</el-menu-item>
<el-menu-item class="right">我的</el-menu-item>
</el-menu>
```
```css
.menu {
display: flex;
justify-content: center;
}
.el-menu-item {
flex: 1;
text-align: center;
}
.right {
margin-left: auto;
}
```
这样就可以实现水平居中并将“我的”菜单项推到最右侧的效果了。需要注意的是,这里的代码可能会影响到其它地方使用`<el-menu>`的样式,如果需要单独控制,可以对该`<el-menu>`增加一个类名,并在样式中使用该类名来控制样式。
相关推荐
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
<template> <el-row class="header"> <el-col :span="24"> 后台管理系统 注销 </el-col> </el-row> <el-row class="content"> <el-col :span="6" class="sidebar"> <el-menu :default-active="activeMenu" class="menu"> <el-menu-item index="1"> 首页 </el-menu-item> <el-menu-item index="/category"> 分类管理 <router-link to="/category"> <el-menu-item>分类管理</el-menu-item> </router-link> </el-menu-item> <el-menu-item index="3"> 系统设置 </el-menu-item> </el-menu> </el-col> <el-col :span="18" class="main"> <router-view ></router-view> </el-col> </el-row> <el-row class="footer"> <el-col :span="24"> 版权所有 © 2022 后台管理系统 </el-col> </el-row> </template>还是会跳到新页面
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)