简体   繁体   English

使背景图像具有响应性

[英]Make Background Image Responsive

Was trying to make my clickable background image responsive on all devices but can seem to wrap my head around it. 试图使我的可点击背景图片在所有设备上都具有响应能力,但似乎将我的头缠住了。 It is showing well on 10" and above screen devices but on lower screen devices, the image is chopped off. I will like to make it responsive on all devices. Any heads up on this will be appreciated. 在10英寸及以上的屏幕设备上显示效果很好,但在较低的屏幕设备上,图像被切掉了。我想使它在所有设备上都具有响应性。对此的任何注意都将受到赞赏。

The code used is found below: 使用的代码如下:

 #range-logo { margin:0 auto; background-image: url(http://midwaycinema7.com/wp-content/uploads/2016/12/bgneww.png); background-repeat: no-repeat; background-position: center center; background-attachment: fixed; background-size: cover; display: block; height: 800px; width: 1240px; } @media only screen and (max-width: 767px) { #range-logo { /* The file size of this background image is 93% smaller * to improve page load speed on mobile internet connections */ background-image: url(http://midwaycinema7.com/wp-content/uploads/2016/12/bgneww.png); } } 
 <a id="range-logo" title="ByPlus Consulting" href="http://midwaycinema7.com/about"></a> 

Use contain property instead of cover if you want to see full image in background. 如果要在后台查看完整图像,请使用contain属性而不是cover

 *{ margin:0; padding:0; } body,html{ width:100%; max-width:100%; margin:0; padding:0; } #range-logo { margin:0 auto; background-image: url(http://midwaycinema7.com/wp-content/uploads/2016/12/bgneww.png); background-repeat: no-repeat; background-position: center center; background-attachment: fixed; background-size: cover; display: block; height: 100vh; width: 100%; } @media only screen and (max-width: 767px) { #range-logo { /* The file size of this background image is 93% smaller * to improve page load speed on mobile internet connections */ background-image: url(http://midwaycinema7.com/wp-content/uploads/2016/12/bgneww.png); background-size:100% 100%; } } 
 <a id="range-logo" title="ByPlus Consulting" href="http://midwaycinema7.com/about"></a> 

Well you can change background-position to 100% as below in media query , this works fine, but this make your image as fixed background on mobile device compare to other visual result on other device. 好了,您可以在media query中将background-position更改为100% ,如下所示,效果很好,但这可以使您在移动设备上作为fixed background的图像与其他设备上的其他视觉效果相比。

 body{ margin:0px; } #range-logo { margin:0 auto; background-image: url(http://midwaycinema7.com/wp-content/uploads/2016/12/bgneww.png); background-repeat: no-repeat; background-position: center center; background-attachment: fixed; background-size: cover; display: block; height: 800px; width: 1240px; } @media screen and (max-width: 767px) { #range-logo { /* The file size of this background image is 93% smaller * to improve page load speed on mobile internet connections */ background-image: url(http://midwaycinema7.com/wp-content/uploads/2016/12/bgneww.png); background-size:100% 100%; } } 
 <a id="range-logo" title="ByPlus Consulting" href="http://midwaycinema7.com/about"></a> 

Try adding this to your media query: 尝试将其添加到您的媒体查询中:

    @media only screen and (max-width: 767px) {
      #range-logo {
        background-image: url(http://midwaycinema7.com/wp-content/uploads/2016/12/bgneww.png);
        background-size:contain;
      }
}

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

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