简体   繁体   English

给div背景图片的宽度

[英]give div the width of background-image

So I am making a gallery-page and I am trying to find a way to scale the divs according to the given background-image. 因此,我正在制作画廊页面,并试图找到一种根据给定的背景图像缩放div的方法。

This is what I have so far: http://codepen.io/anon/pen/FzJDy but this is a problematic solution as if the image is too big, it overflows its' parent div. 这是我到目前为止所拥有的: http : //codepen.io/anon/pen/FzJDy但这是一个有问题的解决方案,好像图像太大了,它的父div就会溢出。 I want to show the full image, so overflow:hidden is not an option. 我想显示完整图像,所以overflow:hidden不是一个选择。

I know that a way to solve this is by using background-image on a div rather than an img tag. 我知道解决此问题的一种方法是在div上而不是img标签上使用background-image and then do background-size: contain but this is also problematic since (I think) it only works when the parent div has a fixed width and height. 然后执行background-size: contain但是这也是有问题的,因为(我认为)它仅在父div具有固定的宽度和高度时才起作用。

Is there a solution to this if both the div and background-image sizes are unknown? 如果div和背景图片的大小都不知道,是否有解决方案?

TL;DR TL; DR

How to scale a picture to its' parent div if the parent div takes same dimensions as containing image? 如果父div与包含图像的尺寸相同,如何将图片缩放到其父div?

thanks. 谢谢。

Remove the following from your .white-content CSS... 从.white-content CSS中删除以下内容...

max-width: 75%;
max-height: 75%;

Then set your .galleryfullsize CSS to... 然后将.galleryfullsize CSS设置为...

.galleryfullsize {
    max-width:100%;
    max-height: 75%;
}

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

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