简体   繁体   English

跨屏幕分辨率调整图像大小

[英]Fitting image size across screen resolutions

I have a div tag like 我有一个像

<div id="MainMenu1" dojotype="dijit.layout.ContentPane"></div>

This div is associated with a css like 该div与css关联,例如

#MainMenu1 
{
height:53px;
background: url(../images/top_banner.png) no-repeat;
background-position:center;
margin:auto;
width:100%;
border:0;
}

I see that the background image is fine on a smaller screen but on a wider screen, it occupies only the center position. 我看到在较小的屏幕上背景图像很好,但在较宽的屏幕上背景图像仅占据中心位置。 I want the image to occupy the full screen even on wider screens and I do not want the image to "repeat". 我希望图像即使在更宽的屏幕上也能占据全屏,并且我不希望图像“重复”。 How would I do this? 我该怎么做?

#MainMenu1 
{
height:53px;
margin:auto;
width:100%;
border:0;
background: url(../images/top_banner.png) no-repeat center center fixed;
-webkit-background-size: cover;
-moz-background-size: cover;
-o-background-size: cover;
background-size: cover;
}

Try this. 尝试这个。 It works perfectly for me. 它非常适合我。 It should fit the background perfectly in the center and reasonably stretch it to whatever screen size the website is being viewed on. 它应该完全适合背景,并适当地将其扩展到正在查看网站的任何屏幕尺寸。

您可以让图像重复表示其覆盖整个空间,也可以使用background-size: cover进行缩放,以覆盖整个区域,同时保持图像的原始纵横比。

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

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