代码之家  ›  专栏  ›  技术社区  ›  franco

使用flex布局的角度7垫卡

  •  1
  • franco  · 技术社区  · 4 年前

    我只想并排放在一排 并且三张卡片将在页面中居中(意味着三张卡片的位置将在中间)

    enter image description here

    我使用这个代码:

    .html文件

      <div fxLayout="row wrap" fxLayout.xs="column" fxLayoutAlign="space-around center" fxLayoutGap="25px">
        <mat-card class="example-card" *ngFor="let member of members" fxFlex="calc(33%-25px)" fxFlex.sm="calc(50%-25px)" >
          <mat-card-header>
            <div mat-card-avatar class="example-header-image"></div>
            <mat-card-title>{{member.title}}</mat-card-title>
            <mat-card-subtitle>{{member.subtitle}}</mat-card-subtitle>
          </mat-card-header>
          <img mat-card-image [src]="member.url" alt="Photo of {{member.title}}">
          <mat-card-content>
            <p>
              {{member.content}}
            </p>
          </mat-card-content>
        </mat-card>
      </div>
    

    .ts码

    @Component({
      selector: 'app-card-view-demo',
      templateUrl: './card-view-demo.component.html',
      styleUrls: ['./card-view-demo.component.scss']
    })
    export class CardViewDemoComponent implements OnInit {
    
      constructor() { }
    
      ngOnInit() {
      }
    
      members: {title: string, subtitle: string, content: string, url: string}[] = [
        {title: 'Title', subtitle: 'Subtitle', content: 'Content here', url: '../../assets/img/app/shiba2.jpg'},
        {title: 'Title', subtitle: 'Subtitle', content: 'Content here', url: '../../assets/img/app/shiba2.jpg'},
        {title: 'Title', subtitle: 'Subtitle', content: 'Content here', url: '../../assets/img/app/shiba2.jpg'},
      ];
    
    }
    

    .content {
        padding: 16px;
    }
    
    .content > mat-card {
        width: 200px;
    }
    

    但是根据这个代码,卡片是垂直的,不在同一行。 每张卡片都有100%的页面大小。

    有人能帮我修改flex布局的代码吗

    0 回复  |  直到 4 年前
    推荐文章