html - 修复了屏幕比例为 100% 的背景图像

标签 html css mobile background-image

有没有人有类似的经历并有解决办法?

我使用下面的 CSS 在手机上显示背景图片,当然我声明了

我无法根据屏幕的高度和宽度显示图像,如果我删除“background-attachment: fixed”,则图像会根据屏幕的高度和宽度调整大小,但图像会根据屏幕的长度居中网页内容而不是屏幕。

谁有更好的解决方案?

#home {
  background: url('../images/hkfmpt_trans.png');
  background-repeat:no-repeat;
  background-position:center; 
  background-attachment: fixed;
  background-size: contain;
}

最佳答案

试试这个

html { 
  background: url('../images/hkfmpt_trans.png') no-repeat center center fixed; 
  -webkit-background-size: cover;
  -moz-background-size: cover;
  -o-background-size: cover;
  background-size: cover;
}

关于html - 修复了屏幕比例为 100% 的背景图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24140113/

相关文章:

javascript - 如何让 TinyMCE 的用户改变背景?

iphone - 使用 Paypal 的移动 P2P 慈善应用程序 - 如何处理安全问题

flutter - (Flutter)使用库flutter_datetime_picker的自定义datepicker模型中的错误

css - 边框干扰绝对定位

javascript - 移动设备检测

javascript - Jquery移动表单数据在单个文件中的两个页面之间提交?

javascript - iframe出现错误,请转到其他网站?

javascript - 在不去掉前导零的情况下增加一个数字

javascript - 无法从显示为 : flex 的父 div 获取 "left"值

css - 根据来自 Controller 的逻辑在 MVC 中设置 View 样式