elementUI 菜单栏下划线如何去除
在使用 elementUI 菜单栏时,默认情况下,选中菜单项后会出现一条下划线。然而,有时我们可能需要去除这条下划线,以获得更简洁美观的效果。
解决这个问题的方法非常简单,只需要在菜单项的 <li> 元素上添加 text-decoration: none; 样式即可。具体步骤如下:
首先,在 <style> 标签中添加以下 CSS 样式:
.el-menu--horizontal > .el-menu-item:hover, .el-menu--horizontal > .el-menu-item:focus, .el-menu--horizontal > .el-menu-item.is-active, .el-menu--horizontal > .el-menu-item.is-opened { text-decoration: none; }
然后,在 HTML 代码中,为选中菜单项的 <li> 元素添加 is-active 类名。例如:
<el-menu :default-active="1" mode="horizontal"> <el-menu-item index="1" is-active>菜单项 1</el-menu-item> <el-menu-item index="2">菜单项 2</el-menu-item> </el-menu>
添加上述 CSS 样式和类名后,选中菜单项的下划线将被去除,呈现出更加清爽简洁的效果。