Mar*_*ski 5 html css background-size
当用户将链接(div)与图像背景挂起时,我想制作缩放效果.
当我想要缩放背景而不是文字时,我不知道该怎么做!我找不到最好的方法.
这是一个代码(不能正常工作):
.light_blue {
display: block;
color: #fff;
background-repeat: no-repeat;
-webkit-background-size: cover;
-moz-background-size: cover;
-o-background-size: cover;
background-size: cover;
background-position: center;
width: 100%;
}
a.light_blue:hover {
text-decoration: none;
color: #fcb428;
}
div.wrap {
height: 33%;
width: 33%;
overflow: hidden;
position: relative;
}
.wrap {
-moz-transition: all .5s;
-webkit-transition: all .8s;
transition: all .8s;
background-position: center center;
}
.wrap:hover {
-webkit-background-size: 120%;
-moz-background-size: 120%;
-o-background-size: 120%;
background-size: 120%;
}
.bg_flat {
position: absolute;
font-family: "Archivo Narrow";
background: url(http://hokejfan.pl/hokej2015/kluby/img/black_bg4.png);
background-size: contain;
bottom: 0px;
padding: 5px;
}
.bg_naglowek {
text-transform: uppercase;
font-size: 29px;
}
.bg_flat2 {
position: absolute;
background: url(../img/black_bg4.png);
background-size: contain;
font-family: "Archivo Narrow";
bottom: 5px;
width: -webkit-calc(100% - 10px);
width: calc(100% - 10px);
padding: 15px;
}Run Code Online (Sandbox Code Playgroud)
<div class="col-sm-4" style="padding: 5px;">
<a href="#news" class="light_blue wrap" style="background-image: url('http://hokejfan.pl/hokej2015/kluby/static/images2/48b51db749e3d9d992a61d289bc3c535.jpg'); height: 180px;">
<div class="bg_flat2">
<b class="bg_naglowek">Hello World</b>
</div>
</a>
</div>Run Code Online (Sandbox Code Playgroud)
如果设置为background-size属性,则无法平滑地为该属性设置动画cover.但你可以通过动画transform来伪造它.由于您只想缩放图像而不是内容,因此您需要一个专门用于显示图像的子元素(在下面的示例中使用伪元素完成).
.wrap {
width: 33%;
padding-bottom: 20%;
overflow: hidden;
position: relative;
transition: all .8s;
background: url(http://hokejfan.pl/hokej2015/kluby/static/images2/48b51db749e3d9d992a61d289bc3c535.jpg);
background-position: center center;
background-size: cover;
}
.wrap::before {
content:"";
position:absolute; top:0;right:0;bottom:0;left:0;
background:inherit;
transition:inherit;
}
.wrap:hover::before {
transform: scale(1.2);
}
.content {
position: relative;
}Run Code Online (Sandbox Code Playgroud)
<div class="wrap">
<div class="content">Content</div>
</div>Run Code Online (Sandbox Code Playgroud)
这是实际用于使用缩放效果的代码..这取决于您设置比例级别。
wrap:hover {
-webkit-transform: scale(1.2);
-ms-transform: scale(1.2);
transform: scale(1.2);
}
Run Code Online (Sandbox Code Playgroud)