css - background
1 <!DOCTYPE html> 2 <html lang="en"> 3 4 <head> 5 <meta charset="UTF-8"> 6 <meta name="viewport" content="width=device-width, initial-scale=1.0"> 7 <meta http-equiv="X-UA-Compatible" content="ie=edge"> 8 <title>Document</title> 9 <style> 10 /* 凡是背景background,一定要有高度!!! */ 11 body{ 12 margin: 0; 13 } 14 15 /* 背景颜色 */ 16 .background-color { 17 height: 500px; 18 /* 19 rgba: rgba->(0,0,0,.7); a透明度 20 hex:#000; 21 rgb:(0,0,0); 22 name:black 23 */ 24 background-color: #000; 25 } 26 27 /* 记得广告常用语隐藏 */ 28 .background-attachment { 29 background-image: url('./酷狗写真.jpg'); 30 /* 31 32 fixed:固定不动 33 scroll:随页面滚动(默认) 34 */ 35 background-attachment: fixed; 36 height: 1000px; 37 } 38 39 /* 背景图片 */ 40 .background-image { 41 background-image: url('./酷狗写真.jpg'); 42 /* 43 url(''); || url(); 44 none:无 45 46 */ 47 height: 1000px; 48 } 49 50 51 /* 背景是否重复 */ 52 .background-repeat { 53 /* 54 round:四周拉宽至100% 55 space:保持缩放比 56 no-repeat:不重复 57 inherit:继承父类 58 initial:继承父类 59 repeat:重复(默认 60 repeat-x:重复x轴 61 repeat-y:重复y轴 62 */ 63 height: 1000px; 64 background-repeat: no-repeat; 65 background-image: url('./酷狗写真.jpg'); 66 } 67 68 .background-position { 69 background-repeat: no-repeat; 70 /* 71 background-position:x轴 y轴 (偏移量) ->百分比、其它单位... 72 top left 73 top center 74 top right 75 center left 76 center center 77 center right 78 bottom left 79 bottom center 80 bottom right 81 x% y% 82 xpos ypos 83 */ 84 background-position: 20px 20px; 85 height: 1000px; 86 background-image: url('./酷狗写真.jpg'); 87 background-color: #000; 88 } 89 90 91 .background-size { 92 background-image: url('./酷狗写真.jpg'); 93 background-size: 10% 20%; 94 /* 95 background-size:x轴 y轴(可数值,可百分比) 96 background-size:x轴+y轴 97 background-size:cover(铺满背景图) 98 background-size:contain(按最佳比例,可能会有空白区域) 99 */ 100 background-size: cover; 101 } 102 103 104 .background { 105 /* 106 background-position:x轴 y轴 (偏移量) 107 background: url('./酷狗写真.jpg') no-repeat top left fixed; 108 109 规范的写法是(顺序官方也是没有限制的,不用的属性可以不用填写,但官方建议如下->为了效率和统一css写法,我们都应该采用这种方式): 110 background-color-> background-image-> background-repeat-> background-attachment-> background-position 111 */ 112 height: 2000px; 113 background: url('./酷狗写真.jpg') no-repeat fixed top left ; 114 background-size: cover; 115 } 116 </style> 117 </head> 118 119 <body> 120 <!-- <div class="background-color"></div> --> 121 <!-- <div class="background-attachment"></div> --> 122 <!-- <div class="background-image"></div> --> 123 <!-- <div class="background-repeat"></div> --> 124 <!-- <div class="background-position"></div> --> 125 <div class="background"></div> 126 </body> 127 128 </html>
分类:
2018-css3
【推荐】还在用 ECharts 开发大屏?试试这款永久免费的开源 BI 工具!
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· ASP.NET Core 模型验证消息的本地化新姿势
· 对象命名为何需要避免'-er'和'-or'后缀
· SQL Server如何跟踪自动统计信息更新?
· AI与.NET技术实操系列:使用Catalyst进行自然语言处理
· 分享一个我遇到过的“量子力学”级别的BUG。
· 为什么AI教师难以实现
· 如何让低于1B参数的小型语言模型实现 100% 的准确率
· AI Agent爆火后,MCP协议为什么如此重要!
· 【译】Visual Studio(v17.13)中新的调试和分析特性
· Draw.io:你可能不知道的「白嫖级」图表绘制神器