5

I am using Angular Material. I have successfully created a navigation bar and a dropdown menu.

It looks like this:

angular material nav

I would like to move the DROPDOWN to the left-hand side. Now, it appears around the centre.

HTML code:

<md-toolbar layout="row" class="md-whiteframe-z3" style="padding: 0px;margin:0px;float: left;">
    <h2>Material NavBar</h2>
    <md-menu>
        <md-button md-menu-origin ng-click="$mdOpenMenu()">Dropdown</md-button>
        <md-menu-content width="2">
            <md-menu-item>
                <md-button>Help</md-button>
            </md-menu-item>
            <md-menu-item>
                <md-button>About</md-button>
            </md-menu-item>
        </md-menu-content>
    </md-menu>
    <md-button aria-label="Go Back">
        Go Back
    </md-button>
    <md-button>Item 1</md-button>
    <md-button>Item 2</md-button>
</md-toolbar>

How can the code be modified to move DROPDOWN to the left just beside the text Material NavBar?

1 Answer 1

3

You just need to add <span flex> </span> in your code.

<md-toolbar layout="row" class="md-whiteframe-z3" style="padding: 0px;margin:0px">
<h2>Material NavBar</h2>
<md-menu>
    <md-button md-menu-origin ng-click="$mdOpenMenu()">Dropdown</md-button>
    <md-menu-content width="2">
        <md-menu-item>
            <md-button>Help</md-button>
        </md-menu-item>
        <md-menu-item>
            <md-button>About</md-button>
        </md-menu-item>
    </md-menu-content>
</md-menu>
<span flex></span>
<md-button aria-label="Go Back">
    Go Back
</md-button>
<md-button>Item 1</md-button>
<md-button>Item 2</md-button>

Here is a working Example. http://codepen.io/next1/pen/RaYNxw

Sign up to request clarification or add additional context in comments.

6 Comments

Such a simple solution, yet I got stuck for a considerable time. Genius!
always use that span element for appropriate alignment of elements.
nextt1, I tried googling to understand more about <span flex> </span> but cannot find a good one. Do you mind providing some link with good documentation on <span flex> </span>?
flex is the important concept. check out the offical doc material.angularjs.org/latest/layout/children
Thanks. I thought flex was a html/css concept. Didn't realize it was a angular material concept.
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.