el-menu>中,<el-menu-item>分别是首页、仓库、安装与教程、客服帮助,要求前四个水平居中且不要让外边距变大。<el-submenu>是我的。靠最右边。效果都是居中,但是我的没有靠右。如果套div,右侧会出现空白,宽度设置100%没有效果
时间: 2024-03-25 09:39:02 浏览: 69
如果套div后右侧仍然会出现空白,可以尝试使用flex布局,将el-menu和el-submenu都放在同一个div中,然后将这个div的display属性设置为flex,将justify-content属性设置为space-between,这样就可以让el-submenu靠右了。
示例代码如下:
```
<div style="display: flex; justify-content: space-between;">
<el-menu :default-active="activeIndex" mode="horizontal" class="menu" style="line-height: 60px;display: flex;justify-content: center;">
<el-menu-item index="1" style="margin: 0;">首页</el-menu-item>
<el-menu-item index="2" style="margin: 0;">仓库</el-menu-item>
<el-menu-item index="3" style="margin: 0;">安装与教程</el-menu-item>
<el-menu-item index="4" style="margin: 0;">客服帮助</el-menu-item>
</el-menu>
<el-submenu index="5">
<template slot="title">我的</template>
<el-menu-item index="5-1">个人中心</el-menu-item>
<el-menu-item index="5-2">退出登录</el-menu-item>
</el-submenu>
</div>
```
这样就可以实现el-menu-item水平居中且不让外边距变大,而el-submenu靠最右边了。如果还有问题,请告诉我具体情况,我会尽力帮助你解决问题。
阅读全文
相关推荐
![pdf](https://img-home.csdnimg.cn/images/20241231044930.png)
![pdf](https://img-home.csdnimg.cn/images/20241231044930.png)
![pdf](https://img-home.csdnimg.cn/images/20241231044930.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)
![](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)