在设备尺寸上居中对齐项目 =< 小

Align items centrally on devices sizes =< small

我有一个卡片组件,它在小型移动设备上的屏幕尺寸上呈现如下面的第一张图片,我将该组件设置为 flex-wrap。当 flex-wrap 处于活动状态时,即使它的容器设置为 w-full 并且我试图以 justify-center 居中,我的图像也会被推到卡片的左侧。我试图仅在设备较小且下方时将图像居中。我试过设置 sm: justify-center 但不起作用。任何人都知道我如何重构才能使此功能正常工作?谢谢

import React from "react"

export default function FeatureCard(props) {
  return (
    <div className="flex flex-row flex-wrap w-2/3 h-auto bg-gray-200 p-2 rounded-lg">
      <div className="flex xl:w-1/3 lg:w-1/3 md:w-1/3 sm:w-full xs:w-full">
        <img src={props.image} />
      </div>
      <div className="flex xl:w-2/3 lg:w-2/3 md:w-2/3 sm:w-full xs:w-full text-center self-center justify-center font-bold">
        <ul>
          {props.features.map(feature => (
            <li>{feature}</li>
          ))}
        </ul>
      </div>
    </div>
  )
}
      <div className="flex flex-row flex-wrap w-full h-auto justify-center -py-2">
        <div className="flex xl:w-1/2 lg:w-1/2 md:w-full sm:w-full xs:w-full h-auto justify-center py-2">
          <FeatureCard
            features={[
              "Modern Website Design",
              "Progressive Web Applications",
              "Content Management Systems",
              "JAMstack",
            ]}
            image={"https://img.icons8.com/color/96/000000/monitor.png"}
          />
        </div>
</div>

所以如果我没理解错的话,你想要 props.image 在小屏幕上居中?

如果您将这样的内容添加到 <div className="flex flex-row flex-wrap w-full h-auto justify-center -py-2"> div:

会怎么样
@media (max-width: 600px) {
    flex-direction: column;
    justify-content: center;
    align-items: center;
    }

它的基本作用是,当屏幕小于 600 像素时,将 flex 方向更改为列而不是行,这在 tailwind-css 中可能转化为:

sm:flex-col sm:justify-center sm:items-center