简体   繁体   English

缩放和缩放CSS背景图片

[英]Zoom and scale css background image

I'd like to zoom and scale in the castle when screen becomes smaller. 屏幕变小时,我想缩放并缩放城堡。 If I set a fixed height, the background is deformed. 如果将高度设置为固定值,则背景会变形。 What can I try ? 我可以尝试什么? JSFIDDLE JSFIDDLE

<div class="background_cover">
<img src="http://www.cdtl.fr/wp-content/uploads/2015/04/Walt_disney_pictures.jpg">
</div>

.background_cover img {
    height: auto;
    min-width: 100%;
    width: 100%;
    background-attachment: scroll;
    background-size: cover;
    background-repeat: repeat;
}

Thanks! 谢谢!

You are defining background properties, but you don't have a background, you have an image. 您正在定义背景属性,但是您没有背景,但是有图像。 You can make a little trick with visibility: 您可以通过可视性制造一些技巧:

 .background_cover { background-image: url(http://www.cdtl.fr/wp-content/uploads/2015/04/Walt_disney_pictures.jpg); background-attachment: scroll; background-size: cover; background-repeat: repeat; } .background_cover img { visibility: hidden; width: 100%; height: auto; } 
 <div class="background_cover"> <img src="http://www.cdtl.fr/wp-content/uploads/2015/04/Walt_disney_pictures.jpg"> </div> 

See your edited fiddle: 查看您编辑过的小提琴:

https://jsfiddle.net/uro8x66a/1/ https://jsfiddle.net/uro8x66a/1/

Here is another solution, if you have to use the image tag instead of a background. 如果您必须使用image标签而不是背景,这是另一种解决方案。 The image scales on hover using the transform property. 图像使用transform属性在悬停时缩放。 The container has overflow hidden and crops the image. 容器已隐藏溢出并裁剪图像。

.background_cover {
    overflow:hidden;
}
.background_cover img:hover {
    transform: scale(1.1); 
}

I forked your JSFiddle. 我分叉了您的JSFiddle。 https://jsfiddle.net/tgLhevrd/1/ https://jsfiddle.net/tgLhevrd/1/

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM