【问题标题】:2 DIVS are overlapping with zoom effect2 DIVS 与缩放效果重叠
【发布时间】:2017-07-04 21:40:02
【问题描述】:

我正在尝试使用 Bootstrap 4 构建一个练习网站(这是我第一次使用它)。我在设计的布局中遇到了一个问题,它可能非常简单,但我无法解决。

<div id="box-container" class="container-fluid">
    <div id="box-row" class="row">
        <div id="header-box1" class="col-lg-6 header-box">
        </div>
        <div id="header-box2" class="col-lg-6 header-box">
        </div>
    </div>
</div>

Full demo | Full code(忽略图片,它们都只是占位符)

查看完整的演示,您会注意到我有 2 个框,我在其中放置了缩放悬停效果。左边的盒子完全按照它应该的方式工作,但是右边的盒子与左边的重叠。我知道这很简单,但我就是想不通。

有什么建议吗? 干杯

【问题讨论】:

  • z-index 设置为 1,悬停时设置为 2。
  • @OfficialAntarctica 没用 :(
  • stackoverflow.com/a/42262836/3798034复制代码,测试它,它可以工作。
  • 尝试将标记更改为&lt;div class="col-lg-6"&gt;&lt;div id="header-box1" class="header-box"&gt;&lt;/div&gt;&lt;/div&gt;&lt;div class="col-lg-6"&gt;&lt;div id="header-box2" class="header-box"&gt;&lt;/div&gt;&lt;/div&gt; 并将height: 100%; 添加到.header-boxoverflow: hidden;#box-row .col-lg-6

标签: javascript jquery html css bootstrap-4


【解决方案1】:

您正在寻找修改背景大小。

.header-box {
    background-position: center;
    background-size:100%;
    transition: all 1s ease;
    -moz-transition: all 1s ease;
    -ms-transition: all 1s ease;
    -webkit-transition: all 1s ease;
    -o-transition: all 1s ease;
}
.header-box:hover{
    background-size:150%;
    -ms-filter: "progid:DXImageTransform.Microsoft.Matrix(M11=1.5, M12=0, M21=0, M22=1.5, SizingMethod='auto expand')"; /* IE8 */
    filter: progid:DXImageTransform.Microsoft.Matrix(M11=1.5, M12=0, M21=0, M22=1.5, SizingMethod='auto expand'); /* IE6 and 7 */ 
}

【讨论】:

  • OP 说这行不通。他们不希望元素在缩放时出现在另一个元素上,并且悬停时更高的 z-index 会使它出现在另一个元素上。
  • 我尝试复制您的确切代码,但对我来说还是一样。
  • @jkarakizi 好的,我误解了你想要的 - 现在试试吧。
【解决方案2】:

将每张图片的 div 放入各自的另一个 div 中,并将溢出设置为无。确保外部 div 的 z-index 更高。

【讨论】:

    【解决方案3】:

    将带有背景的 div 移动到引导列元素中,在引导列上设置 overflow: hidden;,然后将框元素设置为 position: absolute; top: 0; left: 0; right: 0; bottom: 0;

    #header-box1 {
      background-image: url(http://indianapublicmedia.org/arts/files/2012/04/sample-gates-9-940x626.jpg);
    }
    
    #header-box2 {
      background-image: url(http://indianapublicmedia.org/arts/files/2012/04/sample-gates-9-940x626.jpg);
    }
    
    #box-row {
      height: 250px; /* you don't need to modify this */
      overflow: hidden;
      box-sizing: border-box;
    }
    
    .header-box {
      background-position: center;
      transition: all 1s ease;
      -moz-transition: all 1s ease;
      -ms-transition: all 1s ease;
      -webkit-transition: transform 1s ease;
      -o-transition: all 1s ease;
      position: absolute;
      top: 0;
      left: 0;
      right: 0;
      bottom: 0;
    }
    
    .header-box:hover {
      transform: scale(1.5);
      -moz-transform: scale(1.5);
      -webkit-transform: scale(1.5);
      -o-transform: scale(1.5);
      -ms-transform: scale(1.5);
      -ms-filter: "progid:DXImageTransform.Microsoft.Matrix(M11=1.5, M12=0, M21=0, M22=1.5, SizingMethod='auto expand')";
      filter: progid: DXImageTransform.Microsoft.Matrix(M11=1.5, M12=0, M21=0, M22=1.5, SizingMethod='auto expand');
    }
    
    #box-row > .col-lg-6 {
      overflow: hidden;
    }
    <link href="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/4.0.0-alpha.6/css/bootstrap.min.css" rel="stylesheet">
    <div id="box-container" class="container-fluid">
      <div id="box-row" class="row">
        <div class="col-lg-6">
          <div id="header-box1" class="header-box"></div>
        </div>
        <div class="col-lg-6">
          <div id="header-box2" class="header-box"></div>
        </div>
      </div>
    </div>

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-10-03
      • 1970-01-01
      • 2012-09-24
      • 1970-01-01
      相关资源
      最近更新 更多