【发布时间】:2019-02-05 10:09:57
【问题描述】:
我必须在每一行中列出 3 个项目,这对于桌面版本来说效果很好,但在某些设备上响应速度并不快。这些项目在 iPad 上重叠,所以当我单击项目链接时它不会打开。而且有些项目里面的文字比较长,所以我觉得这就是问题
我尝试过使用 display :Flex 和 Grid 但都失败了。
礼品
gift = [{ image_url ,Price of the item, Name of the gift }]
giftResults {
margin: 0 -5px;
}
.giftResults:after {
content: "";
display: table;
clear: both;
}
.error {
color: red;
}
.giftResult {
float: left;
width: 25%;
padding: 0 10px;
}
.gift-container {
width: 940px;
max-width: 100%;
min-width: 768px;
margin: 0 auto;
padding: 0 0;
padding-bottom: 3em;
}
.card {
background-color: #e5474b;
display: inline-block;
/* width: 25%; */
height: 50%;
margin-top: 30px;
width: 33.33333%;
box-shadow: 0 4px 8px 0 rgba(0, 0, 0, 0.2);
padding: 16px;
text-align: center;
}
.card a {
display: block;
}
.card h2 {
padding-bottom: 25px;
font-size: 20px;
height: 35px;
}
.card:hover {
height: 55%;
width: 39%;
}
@media screen and (max-width: 600px) {
.giftResult {
width: 100%;
display: block;
margin-bottom: 20px;
}
.card {
background-color: #e5474b;
max-width: 400px;
display: block;
height: 50%;
margin-top: 30px;
box-shadow: 0 4px 8px 0 rgba(0, 0, 0, 0.2);
padding: 16px;
text-align: center;
width: fit-content;
}
}
<div className="giftResults">
<ul>{ giftDetails }
<li className="giftResult">
<div className="gift-container">
<div className="card">
<img src={props.imageUrl} alt="Item" />
<p>{`$ ${props.price}`}</p>
<a href={props.url} target="_blank" rel="noopener noreferrer">
{props.name}
</a>
</div>
</div>
</li>
</ul>
</div>
【问题讨论】:
-
我建议您考虑使用引导程序来解决您的问题。 Bootstrap 是一种行业标准,它易于使用来对齐项目以获得响应式外观
-
这是我的顶点项目,所以我不应该使用 Bootstrap 或任何库
-
乍一看您的代码,您只有 1 个 css 媒体查询,您应该使用多个来捕获多种设备尺寸
-
对于 Ipad 我不确定宽度
标签: javascript html css flexbox css-grid