简体   繁体   English

wordpress背景图片在移动设备中无响应

[英]wordpress Background image is not responsive in mobile devices

My website is ( https://www.yahoonewsz.com ) and I've uploaded an image on the public_html folder in the server. 我的网站是( https://www.yahoonewsz.com ),并且我已将图像上传到服务器的public_html文件夹中。

I have used the following code for background 我已经使用以下代码作为背景

#main {
  background-image: url("image908.jpg");
  background-attachment: fixed;
  background-position: center;
  background-repeat: no-repeat;
  background-size: cover;
}

in advanced CSS section in WordPress. 在WordPress的高级CSS部分中。

Why is the image not responsive in mobile? 为什么图片在移动设备中没有响应?

Thanks. 谢谢。

You're using background-size: cover which according to the background-size docs "Scales the image as large as possible without stretching the image. If the proportions of the image differ from the element, it is cropped either vertically or horizontally so that no empty space remains." 您使用的是background-size: cover 根据background-size docs进行 background-size: cover ,即“在不拉伸图像的情况下将图像尽可能地缩放。如果图像的比例与元素不同,则将其垂直或水平裁切,以便没有剩余空间。”

What this means is that it's scaling to the smallest "non-squished" size it can be that prevents any empty space in the container. 这意味着它将缩放到最小的“非压缩”尺寸,以防止容器中有任何空白空间。 Since your site (namely the #main ) is roughly 3000px tall on mobile, the background image is being scaled to ~3000px tall. 由于您的网站(即#main )在移动3000px高度大约为3000px ,因此背景图片的尺寸已缩放为3000像素左右。

If you want to constrain it to max width, use background-size: contain which "Scales the image as large as possible without cropping or stretching the image." 如果要将其限制为最大宽度,请使用background-size: contain “在不裁剪或拉伸图像的情况下将图像缩放到尽可能大的比例”。 meaning that it will always fill the container without being cut off. 表示它将始终填充容器而不会被切断。 Note this will give you white space under (or above) the image based on your background-position settings. 请注意,这将根据您的background-position设置为您提供图像下方(或上方)的空白。

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

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