About This Article
This article was created using an automated generation workflow powered by generative AI. Implementation examples from existing materials were compared with official documentation, organizing operational examples, constraints, and reference test results.Verification Status: Partially verified against official documentation and implementation, with reference testing completed. Browser behavior for the fixed demo version has not been confirmed.
Product lists can sometimes be easier to view one at a time on narrow screens. Switch the same card column between a single-item display and a three-item display based on width conditions.
- Key Terms to Know First
- Thinking Through the Processing Flowchart
- Operating the Live Demo
- Key Points of the Code
- When using in production
- Comparing 767 and 768
- Screen width and the width of the area where cards are placed
- Checking display count and operability separately
- If switching does not work correctly
- Verification Scope
- References
- GitHub Sample
Key Terms to Know First
Breakpointis the width boundary where the display switches.
Slideis an item that can be swiped horizontally.
Thinking Through the Processing Flowchart
Read from left to right. Anticipate how changes to the switching width affect the product cards.
flowchart LR
A["表示領域"] --> B["切替幅"] --> C["商品カード"]
Operating the Live Demo
Set the width to 500 and 800. Count the number of visible cards.
How to Read the Results
Below 768 is 1 card. 768 and above is 3 cards.
The width used by the demo is the card area, which is not necessarily the same as the total page width. On narrow clipped screens, you can scroll horizontally to observe the experiment.
Key Points of the Code
Set slidesPerView to 3 for widths of 768 or greater using breakpoints.
The implementation can be checked in the Implementation Code section of the demo screen.
When using in production
Verify whether users can proceed to the next item on smartphones as well, and check keyboard operation.
Comparing 767 and 768
First, enter 500 and click Run. Cards from Product 1 to Product 6 will be generated, and the display area and number of displayed items will appear in the result section. If the display area is 500 pixels, the item count setting is 1. Next, enter 800 and observe the change in the number of displayed items using the same 6 cards. To check boundary conditions, also input 767 and 768 in sequence. The key point of the comparison is to change only the width without altering the card data.
| Specified width | Configured number of displayed items |
|---|---|
| 500, 767 | 1 |
| 768, 800 | 3 |
This table shows the expected results derived from the implementation settings. The actual number of displayed items should be verified against the result section on the screen. On narrow devices, the card area may overflow the screen, or CSS constraints may cause the specified width and measured value to differ. Even if only part of a card is visible on the screen, it does not necessarily mean that the Swiper display count setting has failed. First, compare clientWidth and slidesPerView in the result section.
Screen width and the width of the area where cards are placed
Web pages have widths for the article body, sidebar, card parent elements, and other containers, distinct from the overall screen width. Even on the same computer, the available width for cards differs depending on whether the menu is displayed horizontally or collapsed. Implementations that switch based on screen width sometimes overlook this difference. The purpose of this tutorial is to understand how to determine the display layout by looking at the width of the card area rather than the entire window.
In the Swiper configuration, specify breakpointsBase as container. The basic setting is slidesPerView: 1, which is overridden to 3 when the width is 768 or greater. Since spaceBetween is 12, the 3 cards are arranged including gaps. The card width is not simply 800 divided by 3. The official API documentation currently marks container-based settings with a beta label. Since this tutorial specifies 11.2.5, identical behavior is not guaranteed in future versions.
Input values are restricted between 280 and 850. For example, if 1000 is specified, 850 is used instead. Additionally, 0 and strings that cannot be converted to numbers are replaced with 500 using Number(v)||500. If the width of the result section differs from the input value, first check both this numerical processing and the actual CSS measurements. The implementation creates a div with a set width, appends 6 child elements, and then initializes Swiper. Because the previous instance is destroyed each time, this is not an experiment of repeatedly adding and accumulating cards.
Checking display count and operability separately
Pressing Next moves to the following slide. Observe whether you can reach the last product in both 1-item and 3-item display modes. Being in 3-item display mode does not mean it advances by 3 items at once. The number of displayed items and the step size per movement must be configured separately. Furthermore, this tutorial calls slideNext from an external button and does not include dedicated previous buttons or keyboard navigation settings. Verify additionally in a real browser whether the buttons can be focused via keyboard and whether you can reach the last card.
If switching does not work correctly
If CSS is not loaded properly, cards may stack vertically or the layout may break. Check not only for JavaScript errors but also verify the retrieval results of CSS and modules in the Network tab. If the viewport is less than 768, check the width settings and parent element constraints. If the expected width is exceeded and only the item count setting remains unchanged, verify the version in use and breakpointsBase.
In actual product lists, take into account long product names inside the cards and image aspect ratios. Even if you optimize only the number of displayed items, it becomes unusable if the text is unreadable. Test narrow screens, zoomed displays, and keyboard operations separately, and if usability is poor, provide a standard list as an alternative. Use fictional cards from public educational materials to gather criteria for display design decisions.
Verification Scope
Width calculations executed with Node.js 22.16.0: 500->500, 767->767, 768->768, 800->800, 1000->850, 0->500. Expected item count of 1/3 calculated separately from the 768 threshold. Swiper core and layout not executed.
The targets are current browsers and Swiper 11.2.5 specified in the course material. Communication is required to fetch external CDNs and Mermaid, and tasks remaining include verifying actual material display, actual diagram rendering, and re-confirming the pinned version license. Since official documentation also contains descriptions for other versions, distinguish them from proof of pinned version execution.
References
Official API and Explanations(Accessed November 30, 2026)
