CSS background 背景

  • 在每一层中,下列的值可以出现 0 次或 1 次:
    <attachment>
    <bg-image>
    <position>
    <bg-size>
    <repeat-style>
  • <bg-size> 只能紧接着 <position> 出现,以"/"分割,如: center/80%.
  • <box> 可能出现 0 次、1 次或 2 次。(如果出现 1 次,它同时设定 background-origin 和 background-clip。如果出现 2 次,第一次的出现设置 background-origin,第二次的出现设置 background-clip。)
  • <background-color> 只能被包含在最后一层。只能设置一个背景颜色

指定多个背景层时,使用,分隔每个背景层。

background-attachment 图片的定位方式

属性值作用
fixed相对视口固定
local若元素可滚动,背景将会随着元素的内容滚动 ,
(背景的绘制区域和定位区域是相对于可滚动的区域而不是包含他们的边框)
scroll(默认值)背景会相对元素固定

可以用逗号分隔来为每一张背景图片指定不同的attachment属性值

background-image 背景图片资源地址

  • none
  • url(“xxx”)

background-position 背景图片定位

  • center
  • left
  • right
  • top
  • bottom
  • 通过注明距离某侧的距离 right xx bottom xxx

background-size 背景图片尺寸

  • cover 沿长边进行缩放 保证图片对应边与当前边长度相同
  • contain 沿短边进行缩放
  • 百分比、像素 宽 高 默认值 auto auto

background-repeat 背景图片的重复

  • no-repeat
  • repeat-x / repeat-y
  • space 第一个和最后一个图像会被固定在元素(element)的相应的边上, 同时空白会均匀地分布在图像之间. background-position属性会被忽视
  • round 时而通过添加图片时而同过压缩扩张图像 来占据多出的空间
    可以设置双值: 水平方向 垂直方向

background-clip 背景显示范围范围

  • border-box 默认值
  • padding-box
  • content-box
  • text 可配合字体透明设置渐变色字体

background-origin 背景图片范围

  • padding-box 默认值
  • border-box
  • content-box

当使用 background-attachment 为fixed时,该属性将被忽略不起作用

* {
  background: url('@/assets/dialogs/dialog_header@2x.png') top 0 left 0 / 576px 38px no-repeat,
  url('@/assets/dialogs/dialog_border@2x.png') right 0 top 36px / calc(100% - 316px) no-repeat,
  url('@/assets/dialogs/dialog_body@2x.png') left 0 top 36px / 100% no-repeat;
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值