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 關注
- 183 瀏覽
添加回答
舉報