首页 文章

无法使用flex布局定位角度材料垫卡

提问于
浏览
1

我是Flex Layout的新手,刚开始研究如何使用带有flex布局的角度材料 .

我使用角度材料在角度2中实现了一个简单的登录表单 . 我想使用带有角度材质的flex布局 .

我使用mat-card,我已经对齐了我的表单元素 . 但我想把mat-card放在我的屏幕中央 . 它是水平居中而不是垂直居中

这是我的代码

myform.component.html

<div fxlayout="column" style="background: white;">

<mat-card fxFlex>   
            <form  (ngSubmit)="onSubmit(user.username,user.password)" #myForm="ngForm">

                                <p style="font-size: 30x;">Space Study</p>
                                <p style="font-size: 14px;">Sign In</p>
                                <mat-input-container class="form-row">
                                    <span matTooltip="Username">
                                        <input matInput placeholder=" " id="username" [(ngModel)]="user.username" name="username">
                                    </span>
                                    <span matPrefix><mat-icon>person&nbsp;&nbsp;</mat-icon></span>
                                </mat-input-container>

                                <mat-input-container class="form-row">
                                    <span matTooltip="Password">
                                        <input matInput placeholder=" " id="password" [(ngModel)]="user.password" name="gpassword" [type]="hide ? 'password' : 'text'">
                                    </span>
                                    <span matPrefix><mat-icon>remove_red_eye&nbsp;&nbsp;</mat-icon></span>
                                </mat-input-container>

                    <button mat-raised-button color="primary" type="submit" mat-raised-button>Login</button>

                    <mat-progress-bar mode="indeterminate" *ngIf="showprogressbar"></mat-progress-bar>
            </form>

</mat-card>

</div>

myform.component.css

mat-card{
    width: 350px;
    height: 400px;
    margin:auto;  
    vertical-align:middle;  
}

.form-row{
    display: flex;
}

.form-row input{
    flex: 1;
}

这是我的输出窗口

enter image description here

请问有什么人可以告诉我如何将我的垫卡水平和垂直放置在我的屏幕中央 .

1 回答

  • 0

    我为你的问题创建了stackblitz .

    Here is the stackblitz just I changed to the css

    我添加了css .

    mat-card{
        width: 350px;
        height: 400px;
        display: flex;
        padding: 0;
        margin: 0;
        display: -webkit-box;
        display: -moz-box;
        display: -ms-flexbox;
        display: -webkit-flex;
        align-items: center;
        justify-content: center;
    }
    
    .form-row{
        display: flex;
    }
    
    .form-row input{
        flex: 1;
    }
    

相关问题