【发布时间】:2019-12-19 07:44:42
【问题描述】:
我正在尝试将我的框对齐在一条线上,但当屏幕尺寸为小型手机显示屏时,允许换行并移动到列模式。
我想得到:
Wins Losses Ties Points
随着屏幕缩小:
Wins Losses Ties
Points
HTML
<div fxLayout="row wrap">
<div>Wins</div>
<div>Losses</div>
<div>Ties</div>
<div>Points</div>
</div>
<div>
<div *ngIf="(TeamStandings$ | async) as Data; else loading">
<div fxLayout="row wrap" fxLayoutAlign="space-around center" fxLayout.xs="column">
<div>1</div>
<div>2</div>
<div>3</div>
</div>
</div>
<!-- While data is being returned via Observable, this is shown -->
<ng-template #loading>
Getting Data...
</ng-template>
</div>
这仍然给出:
Wins
Losses
Ties
Points
1
2
3
这让我怀疑 flex-layout 模块是否正常工作,但它包含在我的 app.module.ts 中
import { NgModule } from '@angular/core';
import { AppRoutingModule } from './app-routing.module';
import { BrowserModule } from '@angular/platform-browser';
import { BrowserAnimationsModule } from '@angular/platform-browser/animations';
import { FlexLayoutModule } from '@angular/flex-layout';
import { MaterialModule } from './material/material.module';
import { AppComponent } from './app.component';
@NgModule({
declarations: [
AppComponent
],
imports: [
AppRoutingModule,
BrowserModule,
BrowserAnimationsModule,
FlexLayoutModule,
MaterialModule
],
bootstrap: [AppComponent]
})
export class AppModule { }
每个 sls-number-box 都只是在格式化的框中显示一个标题。但是,无论屏幕分辨率如何,它们都保留在单独的行上。
Wins
Losses
Ties
Points
这些块总是显示为好像它们在一个列中,并且无论屏幕大小如何,都不会向上滚动到同一行。
数字框的 css 设置为 100px 的宽度和高度。如果有办法在 flex 布局中调整块的大小,这也可以删除。请注意,如果我从 CSS 中删除宽度和高度,则框的大小会调整为可用宽度,因此 flex-layout 似乎确实在起作用。
【问题讨论】:
-
请分享可能导致该问题的 sls-number-box 的详细信息
-
@NagaSaiA 我根据建议的答案删除了我的自定义控件,即使是简单的文本也无法正常工作。我认为它一定是 FlexLayoutModule 没有加载,但它在我的 app.module.ts 中。
-
Scott,我使用上述代码 sn-p 创建了 stackblitz,它似乎工作正常-stackblitz.com/edit/angular-jkdjgv?file=src/app/…
-
谢谢。它是将主 div 配置为 display: inline-block;解决了这个问题。
-
感谢@Steven Scott 的确认,我已经发布了与答案相同的帖子
标签: html angular flexbox angular-flex-layout