You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何在div中实现带溢出隐藏的定制化多层并排图片布局?

Absolutely! You can totally pull this off with some simple HTML tweaks and CSS styling. Let me break down a solution that hits all your requirements:


Step 1: Tweak the HTML Structure

First, we'll add classes to differentiate the main image, the partially visible trailing images, and the hidden ones. This gives us precise control over each element:

<div class="roulette">
  <!-- Main visible image -->
  <img src="../application/views/img/cases.png" class="main-img">
  <!-- Trailing images (only the first will show a sliver) -->
  <img src="../application/views/img/cases.png" class="trailing-img">
  <img src="../application/views/img/cases.png" class="trailing-img">
  <!-- Hidden similar images -->
  <img src="../application/views/img/cases.png" class="hidden-img">
  <img src="../application/views/img/cases.png" class="hidden-img">
</div>

Step 2: Apply CSS to Enforce the Design

The CSS will handle the border, overflow hiding, partial visibility of trailing images, and hidden elements:

.roulette {
  /* Add your desired border style */
  border: 3px solid #333;
  /* Hide anything outside the container (including extra images/numbers) */
  overflow: hidden;
  /* Set a fixed width to show main image + a sliver of the first trailing image */
  width: 325px; /* Adjust based on your main image's actual width */
  /* Align images horizontally */
  display: flex;
  align-items: center;
  /* Optional: add padding inside the border */
  padding: 10px;
}

.main-img {
  /* Set your main image's actual dimensions */
  width: 300px;
  height: auto;
}

.trailing-img {
  /* Match main image size */
  width: 300px;
  height: auto;
  /* Pull images overlapping to only show a sliver of the first one */
  margin-left: -275px; /* Adjust this value to control how much of the first trailing image shows */
}

.hidden-img {
  /* Completely hide these images (no space taken up) */
  display: none;
  /* If you need to reserve space for them later, use visibility: hidden; instead */
}

/* If you have numbers outside the border, hide them with this class */
.hidden-number {
  display: none;
}

How It Works
  • Border + Overflow Control: The .roulette container uses overflow: hidden to cut off any content (images, numbers) that sits outside its bordered area.
  • Partial Trailing Image: The negative margin-left on .trailing-img makes the images overlap, so only the first trailing image peeks out next to the main one. Adjust the margin value to make the sliver wider or narrower.
  • Hidden Images: .hidden-img uses display: none to fully hide those images without taking up layout space.
  • Hiding Numbers: If your numbers are separate elements, just add the hidden-number class to them to make them disappear.

内容的提问来源于stack exchange,提问作者Smokey

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.15 03:46:17