首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何在Angular 6中使用HTML在一列中设置6个按钮

问如何在Angular 6中使用HTML在一列中设置6个按钮
EN

Stack Overflow用户
提问于 2019-01-13 22:43:25
回答 1查看 473关注 0票数 0

我正在创建一个机票预订应用程序。在客户选择位置的部分,我想在行中放置6个按钮。我正在使用List来显示我所有的按钮。如图所示,前6个按钮具有正确的位置(红色按钮)。但是蓝色按钮应该在下一行(就像我在图片上显示的那样).How我能做到吗?

​

​

myplaces-list.component.html

代码语言:javascript
复制
<div class="inventory-body" >
 <h3 align="center">Wybierz miejsce</h3>
 <div *ngFor="let myplace of myplaces | async" style="width: 300px;">
 <myplace-details [myplace]='myplace'></myplace-details>
</div>
</div>

myplaces-list.component.ts

代码语言:javascript
复制
export class MyplacesListComponent implements OnInit {

myplaces: Observable<Myplace[]>;
place_id: number;

flight: Flight = new Flight();
submitted = false;
flight_id: number;

places: Observable<Place[]>;

constructor(private myplaceService: MyplaceService, private placeService: PlaceService, private flightService: FlightService,
          private router: Router, private route: ActivatedRoute) { }

ngOnInit() {
this.route.params.subscribe(params => { this.flight_id = params['flight_id']; });
this.flightService.getFlight(this.flight_id).subscribe(t => this.flight = t);
this.reloadData();
}

reloadData() {
this.myplaces = this.myplaceService.fetchEmpDeptDataInnerJoin(this.flight_id);
this.places = this.placeService.getPlacesList();
}}

myplace-details.component.html -我的按钮在这里

代码语言:javascript
复制
<div *ngIf="myplace" style="position: relative; left:-30%; margin-left:10px; margin-bottom:12px">
<div>
<a href="http://localhost:4200/ticket/{{myplace.flight_id}}/{{myplace.place_id}}"
 *ngIf='myplace.active' (click)='updateActive(false)' class="button btn-primary">{{myplace.location}}</a></div>

<span class="button btn-danger" *ngIf='!myplace.active' >{{myplace.location}}   </span>

​

myplace-details.component.ts

代码语言:javascript
复制
export class MyplaceDetailsComponent implements OnInit {

@Input() myplace: Myplace;

place_id: number;

constructor(private myplaceService: MyplaceService, private listComponent: MyplacesListComponent) { }

ngOnInit() {
this.place_id = this.myplace.place_id;
}

updateActive(isActive: boolean) {
this.myplaceService.updatePlace(this.place_id,
  { location: this.myplace.location, active: isActive })
  .subscribe(
    data => {
      console.log(data);
      this.myplace = data as Myplace;
    },
    error => console.log(error));
}}
EN

回答 1

Stack Overflow用户

发布于 2019-01-14 03:31:35

在一个容器中呈现列表并仅用CSS设置它的样式是困难和乏味的。

提供的平面布局的行间距不均匀(列旋转90度),我会考虑替换它或丢弃它。

我的解决方案很简单:飞机有两个座位(ABC,DEF),把它们当作容器,间隔它们添加ie。创建过道的边距。在每个容器中渲染所有座位,并使用flexbox将它们包装到新列中。Here is demo

其他选项:

  • CSS grid https://css-tricks.com/snippets/css/complete-guide-grid/在一个容器中渲染所有内容,并使用网格/列根据您的喜好对其进行整形。(不知道是否允许间距不均匀)带有display:table的
  • 表格/ div创建覆盖整个平面的表格,并调整单元格大小以匹配所需的尺寸。在tr和td上使用nth-child(n)设置适当间距的样式。在*ng中使用多个ng-containers用于选择放置place-details组件的位置以及为间距留空的位置。
票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/54169950

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档