上下文菜单的宽度

时间:2017-07-18 22:26:50

标签: javascript css office-js office-ui-fabric

我正在尝试使用ng-office-ui-fabric的命令栏,并修改uif-contextextual-menu-item的宽度。这是code

<!DOCTYPE html>
<html>
<head>
  <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.6.4/angular.min.js"></script>
  <link rel="stylesheet" href="https://static2.sharepointonline.com/files/fabric/office-ui-fabric-core/2.6.3/css/fabric.min.css" />
  <link rel="stylesheet" href="https://static2.sharepointonline.com/files/fabric/office-ui-fabric-core/2.6.3/css/fabric.components.min.css" />
  <script src="https://cdnjs.cloudflare.com/ajax/libs/ngOfficeUiFabric/0.15.3/ngOfficeUiFabric.min.js"></script>
  <style>
    .menu1.ms-ContextualMenu {
      width: 110px
    }
  </style>
</head>
<body ng-app="YourApp"> 
  <div ng-controller="YourController">
      <uif-command-bar>
        <uif-command-bar-main>
          <uif-command-bar-item>
            <span>14</span>
            <uif-icon uif-type="chevronDown"></uif-icon>
            <uif-contextual-menu uif-is-open="true" class="menu1">
              <uif-contextual-menu-item uif-text="'add'"></uif-contextual-menu-item>
              <uif-contextual-menu-item uif-text="'minus'"></uif-contextual-menu-item>
              <uif-contextual-menu-item uif-type="subMenu">
                <uif-content>Versions</uif-content>
                  <uif-contextual-menu uif-is-open="true">
                    <uif-contextual-menu-item uif-text="'1'"></uif-contextual-menu-item>
                    <uif-contextual-menu-item uif-text="'2'"></uif-contextual-menu-item>
                  </uif-contextual-menu>
                </uif-contextual-menu-item>
            </uif-contextual-menu>
          </uif-command-bar-item>
        </uif-command-bar-main>
      </uif-command-bar>
  </div>
  <script type="text/javascript"> 
    angular.module('YourApp', ['officeuifabric.core', 'officeuifabric.components'])
    .controller('YourController', ['$scope', function ($scope) {}])
  </script> 
</body>
</html>

如您所见,我设法通过.menu1.ms-ContextualMenu修改第一个菜单的宽度(因为它太大了),但子菜单的位置变得不正确。有谁知道如何解决这个问题?

2 个答案:

答案 0 :(得分:1)

只需相应更改CSS中子菜单的left属性:

.ms-ContextualMenu-link.ms-ContextualMenu-link--hasMenu ~ .ms-ContextualMenu {
    left: 108px;
}

修改了你的jsbin:https://jsbin.com/fowahoxiqu/edit?html,output

答案 1 :(得分:0)

the previous answer类似,如果您使用left: 100%而非固定像素宽度,则可以将导航的宽度更改为您心脏的内容,并且它将始终保持在应有的位置。

.menu1.ms-ContextualMenu .ms-ContextualMenu {
    left: 100%;
}