鍍金池/ 問答/HTML/ 請問Element-UI中的NavMenu的寬度怎么改變?

請問Element-UI中的NavMenu的寬度怎么改變?

我在項(xiàng)目中引入elementUi后,視圖是這樣的圖片描述

兩邊有一定的寬度,經(jīng)過審查元素得知,是.el-header中有個(gè)padding:0 20px;造成的,但是我這樣寫,仍然沒有改變樣式

<template>
  <el-menu
    :default-active="activeIndex"
    mode="horizontal"
    @select="handleSelect"
    background-color="#545c64"
    text-color="#fff"
    active-text-color="#ffd04b">
    <el-menu-item index="1">處理中心</el-menu-item>
    <el-menu-item index="2">處理中心</el-menu-item>
    <el-menu-item index="3">處理中心</el-menu-item>
    <el-menu-item index="4">處理中心</el-menu-item>
  </el-menu>
</template>

<script>
    export default {
      name: 'Header',
      data() {
        return {
          activeIndex: '1'
        }
      },
      methods: {
        handleSelect(key, keyPath) {
          console.log(key, keyPath)
        }
      }

    }
</script>

<style scoped>
  .el-header {
    padding: 0!important;
  }
</style>
回答
編輯回答
壞脾滊
  1. ele-ui的樣式是全局樣式,修改它的樣式不能加scoped。

clipboard.png

clipboard.png
這是它的樣式,這么修改:

clipboard.png

  1. 其實(shí)加important并不好,可能會影響到其他地方nav組件的樣式,可以在header的前面加一個(gè)class限制一下,比如加個(gè)nav-group,把修改的組件樣式全部放在nav-group里面:

clipboard.png

2017年2月2日 05:32
編輯回答
青瓷

1:scoped 去掉或樣式寫在統(tǒng)一樣式css里
2:可以按官方教程改某些默認(rèn)樣式

2018年7月31日 13:45