html - 图像在两侧重叠 DIVS

标签 html css css-position z-index

我真的很困惑,希望得到任何指导。

我需要使用 CMS 和 html 编写以下设计代码,但我不知道如何让中心图像与图像右侧和左侧的 div 重叠。我一直在阅读有关相对位置和 z 索引的内容,但我尝试的一切都失败了。一般来说,当我排列三个潜水时,我会使用 float 属性,它工作得很好,但事实证明 z 索引只能与定位元素一起使用。如果有人能让我朝着正确的方向开始,我可能就能弄清楚。

查看我正在尝试编码的设计:https://cdn.shopify.com/s/files/1/0211/8026/files/Example.png?9982

这是基本框架,但我不知道从这里去哪里......

.row-container {
  width: 100%;
  height: 300px;
  margin: auto;
  text-align: center;
  position: relative;
}
.box1 {
  height: 216px;
  width: 288px;
  float: left ; /* <-- This does not work */
  border: 1px solid blue;
}
.image {
  height: 250px;
  width: 350px;
  float: left ; /* <-- This does not work */
  border: 1px solid grey;
}
.box2 {
  height: 216px;
  width: 288px;
  float: left;  /* <-- This does not work */
  border: 1px solid red;
}
<div class="row-container">
  <div class="box1"></div>
  <div class="image">-- Should I use a div for the image?</div>
  <div class="box2"></div>
</div>

最佳答案

尝试一下,如果使用 position:absolute ,效果会更好一点,但由于您想要 float ,因此会出现调整大小问题 Fiddle

缩小以获得效果

.row-container {
  width: 100%;
  height: 300px;
  margin: auto;
  text-align: center;
  position: relative;
}
.box1 {
  position: relative;
  z-index: -1;
  background: green;
  height: 216px;
  width: 288px;
  float: left;
}
.image {
  margin-left: -80px;
  background: red;
  float: left;
  height: 250px;
  width: 200px;
}
.image img {
  width: 300px;
}
.box2 {
  position: relative;
  z-index: -1;
  float: left;
  background: blue;
  height: 216px;
  width: 288px;
}
<div class="row-container">
  <div class="box1"></div>
  <div class="image">
    <img src="http://placekitten.com/300/301" />
  </div>
  <div class="box2"></div>
</div>

关于html - 图像在两侧重叠 DIVS,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27873350/

相关文章:

python - 使用 BeautifulSoup 提取特定的 dl 和 dd 列表元素

html - 背景图片在手机上不会全屏显示

html - CSS:基于 <div> 宽度的文本填充

javascript - ckeditor在数据库中添加html标签

javascript - 跳转到文本区域的下一行,因为我不希望文本到达文本区域的末尾

javascript - 如何右对齐/对齐 Bootstrap 下拉菜单项?

html - 当我缩小浏览器窗口时,段落元素会强制文本跳转到下一行吗?

css - Ionic 3 如何在自定义 ionic 输入中垂直居中文本?

CSS平滑移动动画不起作用

css - div 的垂直和水平对齐 - 第 2 部分