You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Bootstrap CSS:认证页面背景图片无法适配屏幕缩放求助

解决背景图片适配屏幕的问题

你的问题出在原CSS只设置了背景图的位置,没有配置尺寸适配规则,所以窗口缩放时图片不会跟着调整。可以通过添加background-size等属性来实现适配,以下是修改后的代码:

body {
  -webkit-font-smoothing: none;
  background-image: url('../img/logo.png');
  background-position: top left;
  background-size: cover;
  background-repeat: no-repeat;
  /* 可选:让背景固定在视口,滚动页面时不移动 */
  background-attachment: fixed;
}

属性说明:

  • background-size: cover:让图片按比例缩放,完全覆盖整个body区域,多余部分会被裁剪,确保不会出现空白
  • 若希望图片完整显示不裁剪,可替换为background-size: contain,但容器边缘可能出现空白
  • background-repeat: no-repeat:避免图片因尺寸不足重复平铺
  • background-attachment: fixed:可选属性,设置后背景图固定在浏览器视口,页面滚动时位置不变,不需要可删除

内容的提问来源于stack exchange,提问作者mayouy

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.18 18:35:27