css - Angular 响应式表单模板

标签 css angular forms flexbox angular-material

在下图中,左边的是当前表单,但我希望它看起来像右边的(使用 Flexbox?)。我怎样才能做到这一点?我一直无法找到解决方案。我正在使用 Angular Material 而不是 Bootstrap。

enter image description here

<div class="container">

<mat-card>

        <mat-card-title>Filter</mat-card-title>
    
        <mat-card-content>
            <div class="example-container">


                <form class="example-form">

                    <mat-form-field class="example-full-width">
                        <mat-label>Ontvangst op fabriek</mat-label>
                        <select matNativeControl required>
                            <option value="volvo">Volvo</option>
                            <option value="saab">Saab</option>
                            <option value="mercedes">Mercedes</option>
                            <option value="audi">Audi</option>
                        </select>
                    </mat-form-field>
                
                    <mat-form-field class="example-full-width">
                        <mat-label>Losplaats</mat-label>
                        <select matNativeControl required>
                            <option value="volvo">Volvo</option>
                            <option value="saab">Saab</option>
                            <option value="mercedes">Mercedes</option>
                            <option value="audi">Audi</option>
                        </select>
                    </mat-form-field>
                
                    <mat-form-field class="example-full-width">
                        <mat-label>Leverancier</mat-label>
                        <select matNativeControl required>
                            <option value="volvo">Volvo</option>
                            <option value="saab">Saab</option>
                            <option value="mercedes">Mercedes</option>
                            <option value="audi">Audi</option>
                        </select>
                    </mat-form-field>
                
                    <mat-form-field>
                        <input matInput [matDatepicker]="picker" placeholder="Choose a date">
                        <mat-datepicker-toggle matSuffix [for]="picker"></mat-datepicker-toggle>
                        <mat-datepicker #picker></mat-datepicker>
                      </mat-form-field>
                
                   
                </form>

            </div>

            <mat-card-actions>
                <button mat-raised-button (click)="login()" color="primary">Zoeken</button>
            </mat-card-actions>
        </mat-card-content>
    

</mat-card>

</div>

最佳答案

你有两个选择

1。使用 Angular Material

在你的 <mat-form-field> 中放置一个网格https://material.angular.io/components/grid-list/examples

2。使用自定义 CSS

我更改了类名,迟早你必须重构 example-* 东西,我希望没问题。

<mat-form-field class="filter--item">
    <mat-label class="filter--item-label">Leverancier</mat-label>
    <select class="filter--item-select" matNativeControl required>
        <option value="volvo">Volvo</option>
        <option value="saab">Saab</option>
        <option value="mercedes">Mercedes</option>
        <option value="audi">Audi</option>
    </select>
</mat-form-field>
.filter--item {
    display: flex;
}

.filter--item .filter--item-label {
    width: 30%;
}

.filter--item .filter--item-select {
    width: 70%;
}

关于css - Angular 响应式表单模板,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59811441/

相关文章:

javascript - 打开模式时页面滚动到顶部问题

javascript - 选中时下拉标题更改

angular - NgrX 效果重定向 Angular

javascript - angular2中的 typescript ,如何通过这个访问类变量

css - 如何使用 bootstrap 使我的 DIV 出现在彼此下方

css - 带有 Bootstrap 主题的 select2 - 内部折叠

angular - 喷油器错误 "Provider parse errors: Cannot instantiate cyclic dependency!"

html - 同一表单中的不同占位符文本样式

reactjs - 在 redux-form 上使用 React-testing-library 时,表单输入不会改变

python - 无法使用 python mechanize 自动登录(必须 "activate"特定浏览器)