繁体   English   中英

如何设置背景尺寸(高度和宽度)?

[英]How to set background size (height & width)?

我对 JavaScript 很陌生。

到目前为止我的代码:

$("#Stage").css(
  "background-image",
  "url(BG.jpg)",
  "background-attachment", 
  "fixed"
);

我想要做的是将背景图像设置为固定大小,因此可以说: width: 100%height: 100%

您想使用background-size: 100% 确保其浏览器支持与您支持的平台兼容。

$("#Stage").css({ 
     "background-image": "url(BG.jpg)", 
     "background-attachment": "fixed",
     "background-size": "100%"
});

这对我有用(在滑块内):

<!-- CSS -->
<style>
    div.img { 
        background-repeat: no-repeat;
        background-position: center center;
        -webkit-background-size: cover;
        -moz-background-size: cover;
        -o-background-size: cover;
        background-size: cover;
    }
    div.img:nth-of-type(1) {background-image: url('img.jpg');}
    div.img:nth-of-type(2) {background-image: url('img.jpg'); 
    }
</style>

<!-- HTML -->
<div class="img"></div>

这只是简单的 CSS,而不是 jQuery。 您可以在此处阅读有关background-size更多信息: http : //www.w3schools.com/cssref/css3_pr_background-size.asp

暂无
暂无

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

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