1 回答
TA贡献1824条经验 获得超8个赞
您可以简单地使用flex-box
将其应用到父 div 上的位置,并且您的元素将看起来响应式,只需以下代码片段
例子
main {
margin-top: 50px;
margin-bottom: 50px;
}
#items {
display: flex;
flex-wrap: wrap;
text-align: center;
}
.food-item {
border: 2px solid;
border-radius: 5px;
width: 150px;
height: 150px;
margin: 5px;
padding-left: 20px;
padding-right: 20px;
/*margin: auto;*/
transition: 0.4s;
display: inline-block;
text-align: left;
}
<main>
<div id="items">
<br/>
<div class="food-item">
<h4> Fries - 2.49 </h4>
<p> Crispy fresh-cut fries with a side of ketchup. </p>
</div>
<div class="food-item">
<h4> Hot Dog - 3.49 </h4>
<p> Classic American hot dog with mustard, ketchup, and relish on a toasted bun. </p>
</div>
<div class="food-item">
<h4> Hamburger - 3.99 </h4>
<p> A juicy hamburger patty grilled and served on a fresh bun with mustard and ketchup. </p>
</div>
<div class="food-item">
<h4> Buffalo Chicken Wrap - 3.99 </h4>
<p> Crispy buffalo chicken wrapped in a flour tortilla with lettuce and ranch dressing. </p>
</div>
<br/>
<div class="food-item">
<h4> Caesar Salad - 3.49 </h4>
<p> Fresh romaine lettuce served with Caesar salad dressing, croutons, and parmesean cheese. </p>
</div>
<div class="food-item">
<h4> Mac and Cheese - 2.49 </h4>
<p> A sharp three cheese blend served over macaroni and topped with bread crumbs. </p>
</div>
</div>
</main>
- 1 回答
- 0 关注
- 135 浏览
添加回答
举报