2个DIVS重叠,有缩放效果
2 DIVS are overlapping with zoom effect
我正在尝试用 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 个框,我在上面放置了缩放悬停效果。左边的框完全按照它应该的方式工作,但是右边的框与左边重叠。我知道这很简单,但我就是无法理解它。
有什么建议吗?
干杯
您正在寻找修改 background-size。
.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 */
}
将带有背景的 div 移动到 bootstrap 列元素中,在 bootstrap 列上设置 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>
将每个图像的 Div 放在它们自己的另一个 div 中,并将溢出设置为 none。确保外部 div 的 z-index 更高。
我正在尝试用 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 个框,我在上面放置了缩放悬停效果。左边的框完全按照它应该的方式工作,但是右边的框与左边重叠。我知道这很简单,但我就是无法理解它。
有什么建议吗? 干杯
您正在寻找修改 background-size。
.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 */
}
将带有背景的 div 移动到 bootstrap 列元素中,在 bootstrap 列上设置 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>
将每个图像的 Div 放在它们自己的另一个 div 中,并将溢出设置为 none。确保外部 div 的 z-index 更高。