html - 如何在单个 ionic 行中制作可滚动的 ionic 列

标签 html css angular ionic-framework

下图供引用。如何水平对齐所有按钮并使其水平滚动?因此所有按钮都是水平对齐的,没有一个垂直对齐

HTML

    <!-- ITEMS (BOLLEN) VAN GESELECTEERDE AREA -->
    <ion-row scrollX="true" class="scroll-items">
      <ion-col size="3" *ngFor="let item of selectedArea.Items">
        <!-- Items -->
        <ion-button class="item-fab" (click)="selectItem(item)">
          <ion-label class="ion-text-wrap">{{
            item.Descriptions[0].Description
          }}</ion-label>
        </ion-button>
        <ion-button>Test</ion-button>
        <ion-button>Test</ion-button>
        <ion-button>Test</ion-button>
        <ion-button>Test</ion-button>
        <ion-button>Test</ion-button>
        <ion-button>Test</ion-button>
      </ion-col>
    </ion-row>
    <!-- EINDE ITEMS -->

CSS

.scroll-items {
  justify-content: center;
  align-items: ;
  flex-wrap: nowrap;
  overflow-x: scroll !important;
  overflow-y: hidden;
}

scroll

最佳答案

如果从 ion-col 中删除尺寸属性,它将调整为所需的宽度。然后将 col 设置为使用 display: flex 和 nowrap 来实现您可能想要的效果。滚动是由行对齐中心启动的,因此我将其更改为 flex-start。

这对我有用:

HTML

<!-- ITEMS (BOLLEN) VAN GESELECTEERDE AREA -->
<ion-row scrollX="true" class="scroll-items">
  <ion-col *ngFor="let item of selectedArea.Items">
    <!-- Items -->
    <ion-button class="item-fab" (click)="selectItem(item)">
      <ion-label class="ion-text-wrap">{{
        item.Descriptions[0].Description
      }}</ion-label>
    </ion-button>
    <ion-button>Test</ion-button>
    <ion-button>Test</ion-button>
    <ion-button>Test</ion-button>
    <ion-button>Test</ion-button>
    <ion-button>Test</ion-button>
    <ion-button>Test</ion-button>
  </ion-col>
</ion-row>
<!-- EINDE ITEMS -->

CSS

.scroll-items {
  justify-content: flex-start; // changed
  flex-wrap: nowrap;
  overflow-x: scroll !important;
  overflow-y: hidden;
}
.scroll-items ion-col { // added
    display: flex;
    flex-wrap: nowrap;
}

关于html - 如何在单个 ionic 行中制作可滚动的 ionic 列,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/67547564/

相关文章:

html - 如何使用元视口(viewport) "width=device-width"获得 100% 的 div 以完全覆盖页面的宽度

html - 在 div 之后的悬停按钮上更改 div css 属性

angular - :host::ng-deep .class 和 .class :host::ng-deep 之间的区别?

javascript - Angular react 形式 : Producing an array of checkbox values?

javascript - 最快的 Canvas 到 ffmpeg 方法

javascript - 如何在输入字段顶部移动虚拟键盘?

html - CSS 目标主题

css - 如果恰好有 5 个元素,则使用 CSS 选择所有元素

android - 媒体查询不适用于 Chrome for Android

javascript - 放置在 Angular ngOnChanges 生命周期 Hook 中时,函数未运行