我正在尝试用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个盒子,我已经放置了缩放悬停效果。左框正好如何工作,但右框与左边重叠。我知道这很简单,但我无法绕过它。
有什么建议吗? 干杯
答案 0 :(得分:0)
您正在寻找修改背景尺寸。
.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 */
}
答案 1 :(得分:0)
将带有背景的div移动到bootstrap col元素中,在bootstrap cols上设置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>
答案 2 :(得分:0)
将每个图像的Div放在他们自己的另一个div中,并将overflow设置为none。确保外部div的z-index更高。