css教程网 css教程网365css.cn
公告为您打开互联网世界的窗户关于本站
首页/属性速查/颜色与背景

background

背景颜色、图片、位置、尺寸、重复方式的简写。

语法
background: <bg-layer>#, <final-bg-layer>
常用值
#f6f8fc / url(a.png) center/cover no-repeat
初始值
transparent
继承
否

运行效果

示例改成别的值试试,差异一眼能看出来
查看代码
HTML
<div class="bg2"><i>渐变背景</i></div>
CSS
.bg2 { width: 200px; height: 90px; border-radius: 10px; background: linear-gradient(130deg, #2b57ff, #7a4bff 60%, #ff8a5c); display: grid; place-items: center; }
.bg2 i { color: #fff; font: 600 11px/1 ui-monospace, monospace; font-style: normal; }

使用要点

  • 简写会重置所有子属性,混用时注意顺序:color image position/size repeat。
  • 只想改背景色时用 background-color,避免误清掉背景图。