Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

angularjs material Layout, Flex and Offset

1) I am trying to stretch the children divs to 60% and align it in the center but it is not working. I am using flex to stretch the size of the div to 60%. See example http://plnkr.co/edit/eaLjJDbjL1KnOI4jLYyO?p=preview

<div layout="column" layout-align="center">
<div style="background-color:#00A000;height: 40px;" flex="60">

</div>

<div style="background-color:#004444;height: 40px;" flex="60">

</div>

<div style="background-color:#0077b3;height: 40px;" flex="60">

</div>

2) In Angularjs Material document it is mentioned that "to customize the size and position of elements in a layout, use flex, offset, and flex-order attributes", I don't see an example of offset.

like image 235
ask007 Avatar asked Mar 13 '15 14:03

ask007


2 Answers

This is what you need to do..

<div layout="column" layout-align="center">
    <div layout="row" layout-align="center center">
      <div style="background-color:#00A000;height: 40px;" flex="60">
      </div>  
    </div>
    <div layout="row" layout-align="center center">
      <div style="background-color:#004444;height: 40px;" flex="60">
      </div>
    </div>
    <div layout="row" layout-align="center center">
      <div style="background-color:#0077b3;height: 40px;" flex="60">
      </div>
    </div>
</div>

Read more about layout here

like image 170
nitin Avatar answered Nov 02 '22 02:11

nitin


+1 for nitins answer. It really helped me with my issue. Here is the plunker showing his answer in a different way using angular material cards.

The html:

<section class="content-section gridListdemoBasicUsage">
  <div class="row">
    <div class="col-sm-8 col-sm-offset-2">
      <h1 class="text-center">The Different Ways SharePoint can help define your business</h1>
      <!-- Separator -->
      <md-divider ng-style="{'background': 'rgba(255, 102, 51, 0.7)'}"></md-divider>
    </div>
  </div>
  <div layout="row" layout-align="center" data-ng-style="{'width': '100%'}">
    <div class='md-padding' layout="row" layout-align="center" layout-wrap>
      <md-card class="md-whiteframe-9dp" data-ng-style="{'width': '350px', 'border-radius': '6px'}" data-ng-repeat="card in spcVM.serviceCards" layout-padding>
        <a data-ng-if="card.imagePath" ui-sref="{{card.link}}"><img layout-fill src="{{card.imagePath}}" class="img-rounded" alt="{{card.imageAlt}}" /></a>
        <md-card-content>
          <div>
            <h4>{{card.title}}</h4>
            <md-divider ng-style="{'background': 'rgba(255, 102, 51, 0.7)'}"></md-divider>
            <br />
            <p>{{card.mainContent}}</p>
          </div>
        </md-card-content>
        <md-card-footer>
          <div class="md-actions" layout="row" layout-align="center end">
            <md-button ng-click="card.action($event)">View</md-button>
          </div>
        </md-card-footer>
      </md-card>
    </div>
  </div>
</section>

The above is in a container-fluid div.

like image 27
Karnith Avatar answered Nov 02 '22 01:11

Karnith