您好,從您提供的圖片以及原HTML和CSS代碼看,您希望調整購物車頁面樣式,使之更符合指定設計(圖片)要求。
綜合檢視您的原始CSS和畫面需求,以下是調整方向與修改建議:
主要發現及建議
- 整體間距和區塊結構
- 頂層
store-group間距应更寬敞
- 商店名稱底部邊框需調整為虛線或色彩一致
- 商品區塊呈現
- 商品圖片需更大且置左,固定大小,邊角圓潤
- 文字標題需限制兩行且文字截斷
- 價格、數量、總價
- 單價、總價字體及顏色需強調(漸層或深色)
- 數量控制器應更圓滑,並置於中間
- 刪除按鈕
- 紅色icon,且尺寸調整,位置靠右上角
- 鼠標經過改變顏色
- 購物車摘要及結帳按鈕
- 響應式
具體修正CSS範例(包含您的原始碼整合調整)
/* ---------------------------- 基本排版 -------------------------- */
.store-group {
margin-bottom: 24px; /* 增加商品組間距 */
border: 1px solid #e0e0e0;
border-radius: 10px;
background: #fff;
padding: 16px 20px;
box-shadow: 0 1px 3px rgba(0,0,0,0.05);
}
.store-name {
font-size: 1.125rem; /* 18px */
font-weight: 700;
margin-bottom: 16px;
color: #111;
border-bottom: 2px solid #eee;
padding-bottom: 8px;
}
/* ----------------------- 商品清單 ----------------------------- */
.cart-items {
display: flex;
flex-direction: column;
gap: 16px;
}
/* 單筆商品區塊 */
.cart-item {
display: flex;
align-items: center;
gap: 16px;
padding: 12px 0;
border-bottom: 1px solid #f0f0f0;
position: relative;
}
/* 商品圖片 */
.cart-item img {
width: 80px;
height: 80px;
object-fit: cover;
border-radius: 8px;
flex-shrink: 0;
}
/* 左方商品內容 */
.item-details {
flex: 1 1 auto;
min-width: 0;
padding-right: 16px;
}
/* 商品標題限制兩行 */
.item-details .title a.link {
display: -webkit-box;
-webkit-line-clamp: 2;
-webkit-box-orient: vertical;
overflow: hidden;
text-overflow: ellipsis;
font-size: 1rem;
line-height: 1.3rem;
margin-bottom: 8px;
color: #222;
font-weight: 700;
text-decoration: none;
}
.item-details .title a.link:hover {
color: #28a745;
text-decoration: underline;
}
/* 單價文字 */
.unit-price {
font-size: 0.9rem;
color: #555;
margin-bottom: 12px;
}
/* 數量與總價容器 */
.quantity-and-total {
display: flex;
justify-content: space-between;
align-items: center;
gap: 16px;
}
/* 數量控制器 */
.quantity-control {
display: flex;
align-items: center;
border: 1.5px solid #d6d6d6;
border-radius: 24px;
overflow: hidden;
width: 120px;
background: #fafafa;
box-shadow: inset 0 1px 2px rgba(0,0,0,0.05);
}
.quantity-control button {
background: #f9f9f9;
border: none;
width: 36px;
height: 36px;
font-size: 20px;
cursor: pointer;
user-select: none;
transition: background-color 0.25s ease;
display: flex;
justify-content: center;
align-items: center;
color: #666;
}
.quantity-control button:hover {
background: #28a745;
color: #fff;
}
.quantity-control input.in-num {
width: 48px;
border: none;
text-align: center;
font-size: 1rem;
height: 36px;
outline: none;
background: transparent;
color: #222;
font-weight: 600;
}
/* 商品總價 */
.item-total-price {
font-weight: 700;
font-size: 1.1rem;
color: #111;
min-width: 80px;
text-align: right;
}
/* -------------------- 刪除按鈕 ------------------------------- */
.remove-btn {
position: absolute;
top: 8px;
right: 8px;
cursor: pointer;
color: #d32f2f;
font-size: 26px !important;
font-weight: 700;
transition: color 0.25s ease;
background: transparent;
padding: 0;
border: none;
user-select: none;
z-index: 20;
}
.remove-btn:hover {
color: #b71c1c;
}
/* ------------------ 購物車摘要、側欄 ----------------------- */
.cart-sidebar {
border: 1px solid #ddd;
border-radius: 12px;
padding: 32px 28px;
background: #fff;
box-shadow: 0 2px 6px rgb(0 0 0 / 0.1);
max-width: 100%;
}
.cart-sidebar h6 {
font-size: 1.25rem;
font-weight: 700;
margin-bottom: 32px;
color: #222;
}
.cart-sidebar .bg-color-three {
background-color: #f9f9f9;
border-radius: 12px;
padding: 24px;
}
.cart-sidebar .flex-between {
display: flex;
justify-content: space-between;
margin-bottom: 24px;
font-size: 1rem;
color: #444;
font-weight: 600;
}
.cart-sidebar .total-price {
font-size: 1.25rem;
font-weight: 700;
color: #111;
border-top: 2px solid #ddd;
padding-top: 16px;
margin-top: 16px;
}
/* 結帳按鈕 */
.btn-main {
background: linear-gradient(90deg, #28a745 0%, #218838 100%);
color: #fff;
font-weight: 700;
font-size: 1.15rem;
padding: 18px 0;
border-radius: 12px;
border: none;
cursor: pointer;
width: 100%;
text-align: center;
transition: background 0.3s ease;
text-decoration: none;
display: inline-block;
}
.btn-main:hover:not(:disabled) {
background: linear-gradient(90deg, #218838 0%, #19692c 100%);
}
.btn-main:disabled {
background: #a9a9a9;
cursor: not-allowed;
}
/* ------------ 響應式調整 -------------------- */
@media (max-width: 768px) {
.cart-item {
flex-direction: column;
align-items: flex-start;
gap: 12px;
padding: 12px 0 20px;
border-bottom: 1px solid #ebebeb;
}
.item-details {
padding-right: 0;
width: 100%;
}
.quantity-and-total {
width: 100%;
flex-direction: column;
align-items: flex-start;
gap: 8px;
}
.quantity-control {
width: 100%;
max-width: 200px;
}
.item-total-price {
min-width: auto;
font-size: 1.1rem;
text-align: left;
color: #28a745;
}
.remove-btn {
top: 6px;
right: 6px;
font-size: 24px !important;
}
.cart-sidebar {
margin-top: 32px;
max-width: 100%;
padding: 24px 18px;
}
}
HTML小提醒(您的PHP代碼基本Ok)
- 商品價格與總價顯示,建議格式化顯示貨幣符號與小數,如
HK$<?=number_format($row['price'], 2)?> 類似;
- 按鈕
remove-btn 元素內使用 <i class="ph ph-trash">符合現有icon字體套件;
小結
- 主體結構與排版調整,讓間距、字型大小字重更統一並符合現代介面標準。
- 按鈕與互動元素增加過度效果以及懸停(hover)狀態增強反饋。
- 響應式保留原有設計意圖,並做更合理換行與寬度調整。
如果您需要針對特定部分(例如商品標題換行或按鈕動態JS等)進一步調整,歡迎提出!我也可以協助微調PHP輸出格式及數據處理部分。
祝您順利完成樣式更新!