简体   繁体   English

缩放浏览器时全屏背景图片的最小尺寸

[英]Minimum size of fullscreen background image when scaling browser

I am currently trying to modify a wordpress theme that has a full screen image as the homepage. 我目前正在尝试修改具有全屏图像作为首页的wordpress主题。 Right now it scales perfectly fine with the browser, the only problem is it doesn't go smaller then the original image size. 现在,它可以在浏览器中完美缩放,唯一的问题是它的大小不会比原始图像小。 It will go larger and keep its aspect ratio but when you size down the window it doesn't go smaller then the default image size. 它会变大并保持其纵横比,但是当您缩小窗口的大小时,它不会变小,而不是默认的图像大小。

Here is the CSS in the theme for this part: 这是本部分主题中的CSS:

/* full screen slides */
.slides.full {
  position: absolute;
  top: 0;
  left: 0;
  background: #373432;
  width: 100%;
  height: 100%;
  max-height: 100%;
  text-align: center;
  color: #fff;
  text-shadow: 1px 1px 2px rgba(0,0,0,0.2);
}

.slides.full img {
  min-height: 100%;
  min-width: 100%;
  width: auto;
  position: absolute;
  top: 0;
  left: 0;
}

I used another way that made the image go smaller then its original size but it didn't stick to the height of the browser there was just a grey background underneath. 我使用了另一种方法来缩小图像,使其比原始尺寸小,但它不符合浏览器的高度,其下方只有灰色背景。

Is someone able to help me change the css I posted to do what I am trying to achieve? 有人能够帮助我更改发布的CSS以完成我要实现的目标吗? It would be much appreciated! 不胜感激! Thanks. 谢谢。

Have you tried adding max-widht: 100% and max-height: 100% as well to .slides.full img ? 您是否尝试过向.slides.full img添加max-widht: 100%max-height: 100%吗?

It's just a wild guess. 这只是一个疯狂的猜测。 It'd be helpful to see a live example. 观看现场示例会很有帮助。

this will keep the right proportion for the img 这将为img保留正确的比例

   .slides.full img {
    height: auto;
    width: auto;
    max-width: 100%;
    max-height: 100%;
    position: absolute;
    top: 0;
    left: 0;
    }

and changing to height:100% will stretch the img when resized 并更改为height:100%调整大小时height:100%将拉伸img

 .slides.full img {
  max-width:100%; /* lower virsion of IE won't work width max-width */
  width:100%;         /* for IE */
}

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

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