responsive-storefront
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseResponsive Storefront
响应式店面
Overview
概述
Apply mobile-first responsive design patterns to a commerce storefront so that the shopping experience is fast and usable on phones, where the majority of commerce traffic originates. Key patterns include thumb-zone aware layouts, a sticky buy bar that appears on scroll, tap-target sizing, and responsive product grids that reflow without horizontal scrolling.
将移动优先的响应式设计模式应用于电商店面,让购物体验在手机端快速且易用——目前大多数电商流量都来自手机端。核心模式包括适配拇指操作区的布局、滚动时出现的固定购买栏、点击目标尺寸优化,以及无需横向滚动即可自动重排的响应式商品网格。
When to Use This Skill
何时使用该技能
- When more than 50% of storefront traffic comes from mobile devices (check your analytics)
- When building a new storefront from scratch and laying out the CSS architecture
- When auditing an existing storefront for mobile usability issues
- When implementing a product detail page and need a sticky buy button pattern
- When optimizing mobile conversion rate and cart abandonment
- 当超过50%的店面流量来自移动设备时(可查看你的分析数据)
- 当从零搭建新店面、规划CSS架构时
- 当审计现有店面的移动端可用性问题时
- 当实现商品详情页、需要固定购买按钮模式时
- 当优化移动端转化率和购物车弃购率时
Core Instructions
核心操作指南
Step 1: Determine the merchant's platform and choose the right approach
步骤1:确定商家使用的平台并选择合适的方案
| Platform | Recommended Approach | Why |
|---|---|---|
| Shopify | Use a mobile-first OS2.0 theme (Dawn, Sense, Craft) — all are responsive by default; configure mobile layout in Theme Editor | Dawn scores 90+ on mobile PageSpeed out of the box; the Theme Editor exposes mobile-specific layout controls |
| WooCommerce | Use a mobile-first WooCommerce theme (Astra, Kadence, or Flatsome) — all include responsive breakpoints and mobile cart drawer built in | Astra and Kadence score well on Core Web Vitals; Flatsome has built-in sticky header and mobile menu without plugins |
| BigCommerce | Use Cornerstone theme which is mobile-first by design; configure breakpoints in Theme Editor | Cornerstone is BigCommerce's reference theme and passes Google's mobile usability tests |
| Custom / Headless | Write mobile-first CSS with | Full control over all breakpoints and touch interactions; see patterns below |
| 平台 | 推荐方案 | 原因 |
|---|---|---|
| Shopify | 使用移动优先的OS2.0主题(Dawn、Sense、Craft)——所有主题默认都是响应式的;可在主题编辑器中配置移动端布局 | Dawn默认的移动端PageSpeed得分可达90分以上;主题编辑器提供了移动端专属的布局控制选项 |
| WooCommerce | 使用移动优先的WooCommerce主题(Astra、Kadence、Flatsome)——所有主题都内置响应式断点和移动端购物车抽屉 | Astra和Kadence的Core Web Vitals表现优异;Flatsome无需插件即可实现固定头部和移动端菜单 |
| BigCommerce | 使用原生支持移动优先的Cornerstone主题;可在主题编辑器中配置断点 | Cornerstone是BigCommerce的官方参考主题,通过了Google的移动端可用性测试 |
| 自定义/Headless | 使用 | 可完全控制所有断点和触摸交互;参考下方的实现模式 |
Step 2: Configure mobile layout on your platform
步骤2:在你的平台上配置移动端布局
Shopify
Shopify
Theme Editor mobile configuration:
- Go to Online Store → Themes → Customize
- Click the Mobile preview icon in the top toolbar to preview on a phone
- Configure Header settings:
- Set Mobile menu type: Drawer (recommended) or Dropdown
- Enable Sticky header so navigation stays visible while scrolling
- Configure Collection page:
- Set Products per row (mobile) to 2 (standard) or 1 (large cards)
- Enable Filters as a drawer on mobile (not sidebar)
- Configure Product page:
- Enable Sticky add-to-cart in the product section settings
- Set Media placement to stack gallery above product info on mobile (this is the default)
- In Theme settings → Buttons, set button height to at least 44px to meet touch target requirements
Testing mobile performance:
- Open Google PageSpeed Insights (pagespeed.web.dev) and enter your store URL
- Review the Mobile tab — aim for 75+ Performance score
- The most common fix: compress images via Settings → Files and replace large images with WebP versions
主题编辑器移动端配置:
- 进入 Online Store → Themes → Customize
- 点击顶部工具栏的移动端预览图标,预览手机端展示效果
- 配置头部设置:
- 设置移动端菜单类型:抽屉式(推荐)或下拉式
- 开启固定头部,滚动时导航栏保持可见
- 配置分类列表页:
- 设置移动端每行商品数为2(标准)或1(大卡片)
- 开启移动端筛选抽屉(而非侧边栏)
- 配置商品详情页:
- 在商品区块设置中开启固定加入购物车按钮
- 设置媒体资源位置为移动端将图库堆叠在商品信息上方(默认配置)
- 在主题设置 → 按钮中,将按钮高度设置为至少44px,满足触摸目标要求
测试移动端性能:
- 打开Google PageSpeed Insights(pagespeed.web.dev),输入你的店铺URL
- 查看移动端标签页的结果,目标是性能得分达到75分以上
- 最常见的优化方案:通过 Settings → Files 压缩图片,将大体积图片替换为WebP格式
WooCommerce
WooCommerce
Astra theme mobile configuration:
- Go to Appearance → Customize → Header → Mobile Header
- Configure hamburger menu style and position
- Under Appearance → Customize → WooCommerce → Shop Page, set Products per row (mobile) to 2
- Under Appearance → Customize → WooCommerce → Product Page, enable Sticky Add to Cart bar for mobile
- In Appearance → Customize → Global → Container, ensure container width is 100% on mobile (no horizontal padding issues)
Kadence theme mobile configuration:
- Go to Appearance → Customize → WooCommerce → Product Archive
- Set mobile columns to 2 and configure card spacing
- Under Appearance → Customize → WooCommerce → Product Page, enable Sticky Add to Cart
- In Kadence → Header Builder, configure the mobile header layout — Kadence lets you drag elements (logo, menu, cart) to separate mobile header rows
Flatsome theme:
- In Theme Options → WooCommerce → Products, configure mobile product grid columns
- Enable Sticky Add to Cart in Theme Options → WooCommerce → Product
- Flatsome's UX Builder has a mobile preview mode — use it to inspect every page's mobile layout
Astra主题移动端配置:
- 进入 Appearance → Customize → Header → Mobile Header
- 配置汉堡菜单的样式和位置
- 在 Appearance → Customize → WooCommerce → Shop Page 中,设置移动端每行商品数为2
- 在 Appearance → Customize → WooCommerce → Product Page 中,开启移动端固定加入购物车栏
- 在 Appearance → Customize → Global → Container 中,确保移动端容器宽度为100%(避免横向内边距问题)
Kadence主题移动端配置:
- 进入 Appearance → Customize → WooCommerce → Product Archive
- 设置移动端列数为2,配置卡片间距
- 在 Appearance → Customize → WooCommerce → Product Page 中,开启固定加入购物车按钮
- 在 Kadence → Header Builder 中配置移动端头部布局——Kadence支持拖拽元素(logo、菜单、购物车)到不同的移动端头部行
Flatsome主题:
- 在 Theme Options → WooCommerce → Products 中配置移动端商品网格列数
- 在 Theme Options → WooCommerce → Product 中开启固定加入购物车按钮
- Flatsome的UX Builder自带移动端预览模式,可使用它检查每个页面的移动端布局
BigCommerce
BigCommerce
Cornerstone mobile configuration:
- Go to Storefront → My Themes → Customize
- Preview on mobile using the device icon in the toolbar
- Under Global → Layout, configure mobile breakpoints and container padding
- Under Product Page → Images, set gallery layout to Stacked on mobile (image above product info)
- Enable Mobile overlay for the cart — this converts the cart from a sidebar to a bottom sheet on mobile
- Under Category Page → Product Cards, set mobile columns to 2
Cornerstone移动端配置:
- 进入 Storefront → My Themes → Customize
- 点击工具栏的设备图标切换到移动端预览
- 在 Global → Layout 中配置移动端断点和容器内边距
- 在 Product Page → Images 中,设置移动端图库布局为堆叠式(图片在商品信息上方)
- 开启购物车的移动端浮层——将移动端购物车从侧边栏转换为底页样式
- 在 Category Page → Product Cards 中,设置移动端列数为2
Custom / Headless
自定义/Headless
Mobile-first CSS foundations:
css
/* tokens.css */
:root {
--space-sm: 0.5rem;
--space-md: 1rem;
--space-lg: 1.5rem;
--touch-target: 44px; /* WCAG 2.5.5 minimum tap target */
--content-max-width: 1200px;
}
/* Breakpoints: sm=640px, md=768px, lg=1024px */
/* Write base styles for mobile, add min-width queries for larger screens */Responsive product grid (auto-fills columns based on available width):
css
.product-grid {
display: grid;
grid-template-columns: repeat(auto-fill, minmax(min(160px, 100%), 1fr));
gap: var(--space-md);
padding: var(--space-md);
}
@media (min-width: 640px) {
.product-grid { grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); }
}
@media (min-width: 1024px) {
.product-grid { grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); gap: var(--space-lg); }
}
/* Minimum 44px touch target on product card CTA */
.product-card__cta { min-height: var(--touch-target); display: flex; align-items: center; }Sticky buy bar — appears when primary Add to Cart scrolls out of view:
jsx
export function StickyBuyBar({ product, onAddToCart }) {
const [visible, setVisible] = useState(false);
useEffect(() => {
const primaryBtn = document.getElementById('main-add-to-cart');
if (!primaryBtn) return;
const obs = new IntersectionObserver(([e]) => setVisible(!e.isIntersecting));
obs.observe(primaryBtn);
return () => obs.disconnect();
}, []);
return (
<div className={`sticky-buy-bar ${visible ? 'visible' : ''}`} aria-hidden={!visible}>
<img src={product.image} alt="" width="40" height="40" />
<span>{product.name}</span>
<span>${product.price}</span>
<button onClick={onAddToCart} tabIndex={visible ? 0 : -1}>Add to Cart</button>
</div>
);
}css
.sticky-buy-bar {
position: fixed; bottom: 0; left: 0; right: 0;
background: #fff; border-top: 1px solid #e2e8f0;
transform: translateY(100%); transition: transform 0.2s ease; z-index: 50;
padding-bottom: env(safe-area-inset-bottom); /* iPhone home indicator */
display: flex; align-items: center; gap: 0.5rem; padding: 0.75rem 1rem;
}
.sticky-buy-bar.visible { transform: translateY(0); }Mobile cart drawer (bottom sheet pattern):
css
.cart-drawer {
position: fixed; right: 0; top: 0; bottom: 0;
width: min(400px, 100vw); background: #fff;
transform: translateX(100%); transition: transform 0.3s ease;
overflow-y: auto; overscroll-behavior: contain;
}
@media (max-width: 640px) {
.cart-drawer {
top: auto; width: 100vw; height: 85vh;
transform: translateY(100%); border-radius: 16px 16px 0 0;
}
.cart-drawer.open { transform: translateY(0); }
}
.cart-drawer.open { transform: translateX(0); }
/* Checkout button stays within thumb reach */
.cart-checkout-btn {
position: sticky; bottom: 0; background: #fff;
padding: var(--space-md);
padding-bottom: calc(var(--space-md) + env(safe-area-inset-bottom));
}Global 44px touch targets:
css
button, a, input[type="checkbox"], input[type="radio"], select, [role="button"] {
min-height: var(--touch-target);
min-width: var(--touch-target);
}移动优先CSS基础:
css
/* tokens.css */
:root {
--space-sm: 0.5rem;
--space-md: 1rem;
--space-lg: 1.5rem;
--touch-target: 44px; /* WCAG 2.5.5 最低点击目标要求 */
--content-max-width: 1200px;
}
/* 断点: sm=640px, md=768px, lg=1024px */
/* 先编写移动端基础样式,再为更大的屏幕添加min-width媒体查询 */响应式商品网格(根据可用宽度自动填充列数):
css
.product-grid {
display: grid;
grid-template-columns: repeat(auto-fill, minmax(min(160px, 100%), 1fr));
gap: var(--space-md);
padding: var(--space-md);
}
@media (min-width: 640px) {
.product-grid { grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); }
}
@media (min-width: 1024px) {
.product-grid { grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); gap: var(--space-lg); }
}
/* 商品卡片CTA的点击目标最少44px */
.product-card__cta { min-height: var(--touch-target); display: flex; align-items: center; }固定购买栏——当主加入购物车按钮滚动出视野时显示:
jsx
export function StickyBuyBar({ product, onAddToCart }) {
const [visible, setVisible] = useState(false);
useEffect(() => {
const primaryBtn = document.getElementById('main-add-to-cart');
if (!primaryBtn) return;
const obs = new IntersectionObserver(([e]) => setVisible(!e.isIntersecting));
obs.observe(primaryBtn);
return () => obs.disconnect();
}, []);
return (
<div className={`sticky-buy-bar ${visible ? 'visible' : ''}`} aria-hidden={!visible}>
<img src={product.image} alt="" width="40" height="40" />
<span>{product.name}</span>
<span>${product.price}</span>
<button onClick={onAddToCart} tabIndex={visible ? 0 : -1}>Add to Cart</button>
</div>
);
}css
.sticky-buy-bar {
position: fixed; bottom: 0; left: 0; right: 0;
background: #fff; border-top: 1px solid #e2e8f0;
transform: translateY(100%); transition: transform 0.2s ease; z-index: 50;
padding-bottom: env(safe-area-inset-bottom); /* 适配iPhone底部指示条 */
display: flex; align-items: center; gap: 0.5rem; padding: 0.75rem 1rem;
}
.sticky-buy-bar.visible { transform: translateY(0); }移动端购物车抽屉(底页模式):
css
.cart-drawer {
position: fixed; right: 0; top: 0; bottom: 0;
width: min(400px, 100vw); background: #fff;
transform: translateX(100%); transition: transform 0.3s ease;
overflow-y: auto; overscroll-behavior: contain;
}
@media (max-width: 640px) {
.cart-drawer {
top: auto; width: 100vw; height: 85vh;
transform: translateY(100%); border-radius: 16px 16px 0 0;
}
.cart-drawer.open { transform: translateY(0); }
}
.cart-drawer.open { transform: translateX(0); }
/* 结算按钮保持在拇指可及范围内 */
.cart-checkout-btn {
position: sticky; bottom: 0; background: #fff;
padding: var(--space-md);
padding-bottom: calc(var(--space-md) + env(safe-area-inset-bottom));
}全局44px触摸目标设置:
css
button, a, input[type="checkbox"], input[type="radio"], select, [role="button"] {
min-height: var(--touch-target);
min-width: var(--touch-target);
}Best Practices
最佳实践
- Write mobile-first CSS — start with the smallest screen styles and add media queries to enlarge; the reverse approach leads to specificity conflicts
min-width - Use — required for iPhone notch/home indicator; without it, bottom-fixed buttons are obscured
env(safe-area-inset-bottom) - Test with real devices — browser DevTools emulation does not replicate iOS Safari's dynamic viewport height or touch scroll inertia
- Use on scroll containers — prevents body scroll from leaking when users swipe in the cart drawer
overscroll-behavior: contain - Use instead of
100dvhon full-screen elements — iOS Safari's dynamic toolbar causes100vhto include the toolbar height, causing overflow100vh - Set font-size to at least 16px on — prevents iOS Safari from auto-zooming on input focus
<body>
- 编写移动优先的CSS —— 从小屏样式开始编写,再添加媒体查询适配更大的屏幕;反向的编写方式会导致样式优先级冲突
min-width - 使用—— 适配iPhone刘海/底部指示条的必要属性,否则底部固定按钮会被遮挡
env(safe-area-inset-bottom) - 使用真实设备测试 —— 浏览器开发者工具的模拟无法复现iOS Safari的动态视口高度或触摸滚动惯性
- 在滚动容器上使用—— 避免用户在购物车抽屉内滑动时触发页面主体滚动
overscroll-behavior: contain - 全屏元素使用替代
100dvh—— iOS Safari的动态工具栏会导致100vh包含工具栏高度,引发溢出问题100vh - 的font-size至少设置为16px —— 避免iOS Safari在输入框聚焦时自动缩放页面
<body>
Common Pitfalls
常见问题
| Problem | Solution |
|---|---|
| Sticky buy bar obscures footer or checkout button | Hide the bar when the footer or checkout button enters the viewport using IntersectionObserver |
| iOS Safari layout jumps when toolbar appears | Use |
| Font too small to read without pinch-zooming | Set |
| Cart drawer body scroll | Apply |
| Product images load slowly on mobile | Specify |
| 问题 | 解决方案 |
|---|---|
| 固定购买栏遮挡页脚或结算按钮 | 使用IntersectionObserver监听,当页脚或结算按钮进入视口时隐藏固定购买栏 |
| 工具栏出现时iOS Safari布局跳动 | 使用 |
| 字体太小,需要捏合缩放才能阅读 | 给body设置 |
| 购物车抽屉滑动时触发页面主体滚动 | 抽屉打开时给 |
| 移动端商品图片加载慢 | 明确设置 |
Related Skills
相关技能
- @mega-menu-builder
- @quick-view-modal
- @accessibility-commerce
- @storefront-theming
- @mega-menu-builder
- @quick-view-modal
- @accessibility-commerce
- @storefront-theming