我已经为桌面创建了网格布局,但对于移动设备,它是不同的. 下面是桌面版的照片

enter image description here

我使用以下代码创建了此布局:

 <div class="grid grid-flow-col grid-rows-2 gap-1 ml-auto justify-center mt-2.5">
            <img src="{{view url='images/icons/ic_mastercard.svg'}}" width="44" height="30" alt="mastercard" loading="lazy">
            <div class="w-[44px] h-[30px] hidden md:block"></div>
            <img src="{{view url='images/icons/ic_maestro-white-bg.svg'}}" width="44" height="30" alt="mastercard" loading="lazy">
            <img src="{{view url='images/icons/ic_gb.svg'}}" width="44" height="30" alt="GB" loading="lazy">
            <img src="{{view url='images/icons/ic_visa.svg'}}" width="44" height="30" alt="visa" loading="lazy">
            <img src="{{view url='images/icons/ic_bancontact-white-bg.svg'}}" width="44" height="30" alt="Bancontact" loading="lazy">
            <img src="{{view url='images/icons/ic_american-ex.svg'}}" width="44" height="30" alt="american exprerss" loading="lazy">
            <img src="{{view url='images/icons/ic_eps-white-bg.svg'}}" width="44" height="30" alt="EPS" loading="lazy">
            <img src="{{view url='images/icons/ic_paypal.svg'}}" width="44" height="30" alt="paypal" loading="lazy">
            <img src="{{view url='images/icons/ic_multibanco-white-bg.svg'}}" width="44" height="30" alt="Multibanco" loading="lazy">
            <img src="{{view url='images/icons/ic_klarna-pink-bg.svg'}}" width="44" height="30" alt="klarna" loading="lazy">
            <img src="{{view url='images/icons/ic_giropay-white-bg.svg'}}" width="44" height="30" alt="Giropay" loading="lazy">
            <img src="{{view url='images/icons/ic_gpay-white-bg.svg'}}" width="44" height="30" alt="google pay" loading="lazy">
            <img src="{{view url='images/icons/ic_alipay-white-bg.svg'}}" width="44" height="30" alt="Alipay" loading="lazy">
            <img src="{{view url='images/icons/ic_applepay-white-bg.svg'}}" width="44" height="30" alt="apple pay" loading="lazy">
            <img src="{{view url='images/icons/sofort.svg'}}" width="44" height="30" alt="Sofort" loading="lazy">
    </div>

现在,问题是,当我切换到手机时,布局保持不变,但相反,手机上的布局应该如下图所示

enter image description here

如何使用网格创建如此照片所示的移动布局?

推荐答案

你必须为你想要的行为用flexflex-wrap属性替换grid布局.


Try the following code:
<div class="mx-auto mt-2.5 flex w-96 flex-wrap items-center justify-center gap-1">
  <img src="{{view url='images/icons/ic_mastercard.svg'}}" width="44" height="30" alt="mastercard" loading="lazy" />
  <div class="hidden h-[30px] w-[44px] md:block"></div>
  <img src="{{view url='images/icons/ic_maestro-white-bg.svg'}}" width="44" height="30" alt="mastercard" loading="lazy" />
  <img src="{{view url='images/icons/ic_gb.svg'}}" width="44" height="30" alt="GB" loading="lazy" />
  <img src="{{view url='images/icons/ic_visa.svg'}}" width="44" height="30" alt="visa" loading="lazy" />
  <img src="{{view url='images/icons/ic_bancontact-white-bg.svg'}}" width="44" height="30" alt="Bancontact" loading="lazy" />
  <img src="{{view url='images/icons/ic_american-ex.svg'}}" width="44" height="30" alt="american exprerss" loading="lazy" />
  <img src="{{view url='images/icons/ic_eps-white-bg.svg'}}" width="44" height="30" alt="EPS" loading="lazy" />
  <img src="{{view url='images/icons/ic_paypal.svg'}}" width="44" height="30" alt="paypal" loading="lazy" />
  <img src="{{view url='images/icons/ic_multibanco-white-bg.svg'}}" width="44" height="30" alt="Multibanco" loading="lazy" />
  <img src="{{view url='images/icons/ic_klarna-pink-bg.svg'}}" width="44" height="30" alt="klarna" loading="lazy" />
  <img src="{{view url='images/icons/ic_giropay-white-bg.svg'}}" width="44" height="30" alt="Giropay" loading="lazy" />
  <img src="{{view url='images/icons/ic_gpay-white-bg.svg'}}" width="44" height="30" alt="google pay" loading="lazy" />
  <img src="{{view url='images/icons/ic_alipay-white-bg.svg'}}" width="44" height="30" alt="Alipay" loading="lazy" />
  <img src="{{view url='images/icons/ic_applepay-white-bg.svg'}}" width="44" height="30" alt="apple pay" loading="lazy" />
  <img src="{{view url='images/icons/sofort.svg'}}" width="44" height="30" alt="Sofort" loading="lazy" />
</div>

Html相关问答推荐

springBoot + Thymeleaf:属性中的UTF-8

值更新时旋转数字动画

在浮动元素旁边垂直居中

需要关于HTML的建议

邮箱追踪器-有效,但在Gmail客户端中是否可以显示问号图标以外的其他内容?

未知高度正在应用于前标记

如何在排序上重用参数?

Style=背景图像URL引用变成&;Quot;

当文本添加到元素中时,将元素拉到页面上

你将如何为手机制作导航栏

Tailwind CSS 忽略我的元素的填充

如何将图像放在其内部按钮下方

网格中的图像zoom 不正确

如何在悬停时使用 CSS 更改许多同级元素

停止 Bootstrap 5 输入调整 CSS 网格单元的高度

四开:如何右对齐 PDF *和* HTML 中的文本

如何使Bootstrap 5卡可点击

获取链接到功能的网页表单

AWS SES:如何正确使用 CSS

所有幻灯片上的 Quarto RevealJS 标题