[英]Zoom in on image on hover using transform: scale, still making image bigger from outside
我如何制作它以使图像放大自身而不会使外部更大,例如这就是我想要的,我试图实现这个但它不起作用: http : //jsfiddle.net/7vY7v/ 130 / 。 我究竟做错了什么?
我正在使用bootstrap,并在imgs上使用img-responsive
类。
以下是我到目前为止所做的演示: http : //codepen.io/anon/pen/XJzexN
码:
HTML:
<html>
<head>
<title></title>
<meta name="viewport" content="width=device-width, initial-scale=1.0 user-scalable=no">
<link href='http://fonts.googleapis.com/css?family=Lato:100,300,400,700,900' rel='stylesheet' type='text/css'>
<link href='http://fonts.googleapis.com/css?family=Roboto:400,100,300,500,700,900' rel='stylesheet' type='text/css'>
<link href='http://fonts.googleapis.com/css?family=Open+Sans:400,300,600,700,800' rel='stylesheet' type='text/css'>
<link href="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.2/css/bootstrap.min.css" rel="stylesheet">
<link href="http://maxcdn.bootstrapcdn.com/font-awesome/4.2.0/css/font-awesome.min.css" rel="stylesheet">
<link rel="stylesheet" type="text/css" href="css/style.css">
</head>
<body>
<div class="container">
<div class="row">
<div class="col-md-6 img-wrapper">
<img src="https://unsplash.it/800" alt="" class="img-responsive">
</div>
<div class="col-md-6 img-wrapper">
<img src="https://unsplash.it/800" alt="" class="img-responsive">
</div>
</div>
<div class="pushdown"></div>
<div class="row">
<div class="col-md-6 img-wrapper">
<img src="https://unsplash.it/800" alt="" class="img-responsive">
</div>
<div class="col-md-6 img-wrapper">
<img src="https://unsplash.it/800" alt="" class="img-responsive">
</div>
</div>
</div>
<div class="container-fluid">
<div class="row">
<div class="people">
</div>
</div>
</div>
</body>
</html>
CSS:
.img-wrapper {
display: inline-block;
overflow: hidden;
}
.img-wrapper img {
-webkit-transition: all .5s ease;
-moz-transition: all .5s ease;
-ms-transition: all .5s ease;
-o-transition: all .5s ease;
transition: all .5s ease;
vertical-align: middle;
}
.img-wrapper img:hover {
transform:scale(1.5);
-ms-transform:scale(1.5); /* IE 9 */
-moz-transform:scale(1.5); /* Firefox */
-webkit-transform:scale(1.5); /* Safari and Chrome */
-o-transform:scale(1.5); /* Opera */
}
将您的HTML结构更改为:
<div class="col-md-6">
<div class="img-wrapper">
<img src="https://unsplash.it/800" alt="" class="img-responsive">
</div>
</div>
元素似乎在扩展的原因是因为父.col-md-6
元素上有padding-left
( padding-left
/ padding-right
of 15px
)。
通过将直接父元素更改为.img-wrapper
,可以有效地替换它并隐藏溢出。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.