页面背景不显示整个图像

时间:2015-10-27 16:00:00

标签: javascript html css

我有一个带有背景图片的网站,随机选择javascript:

- (void)layoutSubviews {
    [super layoutSubviews];

    // Constrain the image view's content size to match the stackview's width.
    self.imageView.constrainedSize = CGSizeMake(self.stackView.frame.size.width, self.stackView.frame.size.width);

    [super layoutSubviews];

我已将背景设置为包含15个背景的document.body.style.background= 'url('+randombgs[num]+')'; 数组中的图像。但是背景被切断了,整个图像都没有显示出来(见下图)

这就是我所看到的:
This is what I see

这是我应该看到的 This is what I should see

如何解决此问题,以便我的浏览器显示整个图像,而不是95%?

2 个答案:

答案 0 :(得分:0)

使用CSS background-size属性:

body {
  background-size: contain;
}

图像适合您的容器。

答案 1 :(得分:0)

您可以在CSS中使用background-size属性(值为contain)。

有关详细信息,请参阅http://www.w3schools.com/cssref/css3_pr_background-size.asp

IE8及更低版本不支持:仅http://caniuse.com/#feat=background-img-opts