在设备尺寸= <小的情况下集中对齐项目

时间:2020-07-15 11:14:54

标签: css flexbox tailwind-css

我有一个卡片组件,它在较小的移动设备上方的屏幕尺寸上像下面的第一个图像一样呈现,我将该组件设置为flex-wrap。当flex-wrap处于活动状态时,即使我的图像的容器设置为w满,我的图像也被推到卡的左侧,并且我尝试以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>

Desktop Display

Mobile display

1 个答案:

答案 0 :(得分:1)

所以,如果我理解正确,您是否希望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;
    }

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

sm:flex-col sm:justify-center sm:items-center
相关问题