技术频道


CSS 简写背景语法

body {
  background-image: url('你的图片路径.jpg');
  background-size: cover;       /* 覆盖整个视口 */
  background-position: center;  /* 图片居中 */
  background-repeat: no-repeat; /* 不重复 */
  background-attachment: fixed; /* 可选:固定背景不随滚动移动 */
}
 

简写形式 MARK:


body {
  background: url('你的图片路径.jpg') center/cover no-repeat fixed;
}

  • cover - 确保图片始终覆盖整个元素,可能会裁剪图片
  • no-repeat - 防止图片平铺重复
  • center - 使图片居中显示
  • fixed - 创建视差效果,背景不随页面滚动(可选)

如要背景随内容滚动,可以移除 background-attachment: fixed 属性。

 

CommandNotFound ⚡️ 坑否 - 其他频道扩展阅读:




发表评论