我有一个卡片组件,它在小型移动设备上方的屏幕尺寸上呈现如下第一张图片所示的效果,我将该组件设置为 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">
会怎样?分区:
@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
关于css - 将元素在设备尺寸上居中对齐 =< 小,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62913611/