如何在 md-toolbar 中将元素定位到右侧?

How to position elements to the right in md-toolbar?

我在工具栏中使用 FAB 快速拨号。但是我无法让它浮动到工具栏的右侧。我试过 float: right 但没有成功。此外,尝试了 flex offset="55",但是当 window 调整大小时这不起作用。本质上,无论 window 大小如何,我都希望按钮位于蓝色工具栏容器内的最右侧。

查看下面的照片和代码:

<md-toolbar layout-fill layout-padding layout="row" style="background-color: #3F51B5;color:white;text-align:text-center;">
    <div layout="row">
        <i class="fa fa-users fa-2x" flex></i>
        <h1 class="md-title" style="color:white">Org Chart</h1>                                 
    </div>  
    <div class="lock-size" flex offset="55">
        <md-fab-speed-dial md-direction="left" ng-class="md-fling">
            <md-fab-trigger>
                <md-button aria-label="menu" class="md-fab md-accent">
                    <md-tooltip>
                      Actions
                    </md-tooltip>
                    <md-icon md-svg-src="img/icons/ic_view_module_48px.svg"></md-icon>
                </md-button>
            </md-fab-trigger>
            <md-fab-actions>
                <md-button aria-label="view" class="md-fab md-raised md-mini" >
                    <md-tooltip>
                      View Chart
                    </md-tooltip>                               
                    <md-icon md-svg-src="" style="color:black" ng-show="cDP.read" ng-click="paneShowFn('read')"></md-icon>
                </md-button>
                <md-button aria-label="add" class="md-fab md-raised md-mini" >
                    <md-tooltip>
                      Add Chart
                    </md-tooltip>                               
                    <md-icon md-svg-src="img/icons/ic_add_48px.svg" style="color:black" ng-show="cDP.insert" ng-click="paneShowFn('insert')"></md-icon>
                </md-button>
                <md-button aria-label="Settings" class="md-fab md-raised md-mini" >
                    <md-tooltip>
                      Security Access
                    </md-tooltip>                               
                    <md-icon md-svg-src="img/icons/ic_add_48px.svg" style="color:black" ng-show="cDP.permission" ng-click="paneShowFn('permission')"></md-icon>
                </md-button>                                
                <md-button aria-label="edit" class="md-fab md-raised md-mini" style="color:black" ng-show="cDP.update" ng-click="paneShowFn('update')">
                    <md-tooltip>
                      Edit Chart
                    </md-tooltip>                               
                    <md-icon md-svg-src="img/icons/ic_edit_48px.svg" style="color:black"></md-icon>
                </md-button>                                
            </md-fab-actions>
        </md-fab-speed-dial>
    </div>  
</md-toolbar>

此解决方案适用于 ANGULAR MATERIAL v1.X,如果您需要 UNIVERSAL/ANGULAR MATERIAL v2 解决方案,请检查@experimenter 答案

如果您有 md-toolbar 对齐正确内容的最简单方法如下:

    <md-toolbar>
        <div class="md-toolbar-tools">
            <h3>You text</h3>
            <span flex></span>
            <ANY>your right content</ANY>
        </div>
    </md-toolbar>

span中的flex属性会覆盖space之间的内容。这是文档中的官方方式。

在你的例子中,你只需要:

<md-toolbar>
    <div class="md-toolbar-tools">
        <div layout="row">
            <i class="fa fa-users fa-2x" flex></i>
            <h1 class="md-title" style="color:white">Org Chart</h1>
        </div>
        <span flex></span>
        <md-fab-speed-dial md-direction="left" ng-class="md-fling">
            <md-fab-trigger>
                <md-button aria-label="menu" class="md-fab md-accent">
                    <md-tooltip>
                        Actions
                    </md-tooltip>
                    <md-icon md-svg-src="img/icons/ic_view_module_48px.svg"></md-icon>
                </md-button>
            </md-fab-trigger>
            <md-fab-actions>
                <md-button aria-label="view" class="md-fab md-raised md-mini">
                    <md-tooltip>
                        View Chart
                    </md-tooltip>
                    <md-icon md-svg-src="" style="color:black" ng-show="cDP.read" ng-click="paneShowFn('read')"></md-icon>
                </md-button>
                <md-button aria-label="add" class="md-fab md-raised md-mini">
                    <md-tooltip>
                        Add Chart
                    </md-tooltip>
                    <md-icon md-svg-src="img/icons/ic_add_48px.svg" style="color:black" ng-show="cDP.insert" ng-click="paneShowFn('insert')"></md-icon>
                </md-button>
                <md-button aria-label="Settings" class="md-fab md-raised md-mini">
                    <md-tooltip>
                        Security Access
                    </md-tooltip>
                    <md-icon md-svg-src="img/icons/ic_add_48px.svg" style="color:black" ng-show="cDP.permission" ng-click="paneShowFn('permission')"></md-icon>
                </md-button>
                <md-button aria-label="edit" class="md-fab md-raised md-mini" style="color:black" ng-show="cDP.update" ng-click="paneShowFn('update')">
                    <md-tooltip>
                        Edit Chart
                    </md-tooltip>
                    <md-icon md-svg-src="img/icons/ic_edit_48px.svg" style="color:black"></md-icon>
                </md-button>
            </md-fab-actions>
        </md-fab-speed-dial>
    </div>
</md-toolbar>

或者您可以为此使用 class:

.fill-space {
  // This fills the remaining space, by using flexbox.
  // Every toolbar row uses a flexbox row layout.
  flex: 1 1 auto;
}
<md-toolbar color="primary">
  <span>Application Title</span>

  <!-- This fills the remaining space of the current row -->
  <span class="fill-space"></span>

  <span>Right Aligned Text</span>
</md-toolbar>

这个解决方案也来自一个规范。