css关于背景图片的设置1

如果你想让背景图片不重复显示,你可以使用 background-repeat 属性,并设置为 no-repeat。例如:

body {
  background-image: url('img/3.jpg');
  background-repeat: no-repeat;
}

如果你想让背景图片填充整个背景区域,但不改变图片的比例,你可以使用 background-size 属性,并设置为 contain 或者 cover。例如:

body {
  background-image: url('img/3.jpg');
  background-repeat: no-repeat;
  background-size: contain; /* 或者 cover */
}

如果你想让背景图片居中显示,你可以使用 background-position 属性,并设置为 center
。例如:

body {
  background-image: url('img/3.jpg');
  background-repeat: no-repeat;
  background-position: center;
}
  • 使用 background-color 属性设置背景颜色,与背景图片相配合,填补两边空白
    。例如:
body {
  background-color: #b0c4de; /* 设置背景颜色 */
  background-image: url('img/3.jpg');
  background-repeat: no-repeat;
}
  • 使用 background-origin 属性设置背景图片的原点位置,可以是内容区、内边距区或者边框区
    。例如:
body {
  background-image: url('img/3.jpg');
  background-repeat: no-repeat;
  background-origin: border-box; /* 设置背景图片的原点为边框区 */
}
  • 使用 background-clip 属性设置背景图片的裁剪范围,可以是内容区、内边距区或者边框区
    。例如:
body {
  background-image: url('img/3.jpg');
  background-repeat: no-repeat;
  background-clip: padding-box; /* 设置背景图片的裁剪范围为内边距区 */
}
  • 使用 background-attachment 属性设置背景图片是否随着页面滚动或者固定在视口
    。例如:
body {
  background-image: url('img/3.jpg');
  background-repeat: no-repeat;
  background-attachment: fixed; /* 设置背景图片固定在视口 */
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值