一篇文章带你了解CSS3 背景知识
三、属性1. background-origin 属性
CSS3 background-origin 属性指定在背景图像定位在哪里.
这个属性有三个不同的值:
border-box :背景图像从边框的左上角开始。
padding-box :(默认)背景图像从左上角的填充边缘。
content-box :背景图像从左上角的内容
下面的例子说明了background-origin属性:
#example1 { border: 10px solid black; padding: 35px; background: url(img/fy_indexBg.jpg); background-repeat: no-repeat; }
#example2 { border: 10px solid black; padding: 35px; background: url(img/fy_indexBg.jpg); background-repeat: no-repeat; background-origin: border-box; }
#example3 { border: 10px solid black; padding: 35px; background: url(img/fy_indexBg.jpg); background-repeat: no-repeat; background-origin: content-box; }
完整代码:
<!DOCTYPE html><html lang="en"><head> <meta charset="UTF-8"> <title>编程字典</title> <style> #example1 { border: 10px solid black; padding: 35px; background: url(img/fy_indexBg.jpg); background-repeat: no-repeat; }
#example2 { border: 10px solid black; padding: 35px; background: url(img/fy_indexBg.jpg); background-repeat: no-repeat; background-origin: border-box; }
#example3 { border: 10px solid black; padding: 35px; background: url(img/fy_indexBg.jpg); background-repeat: no-repeat; background-origin: content-box; } </style></head><body>
<p>没有 background-origin (padding-box 默认):</p> <div id="example1"> <h2>Lorem Ipsum Dolor</h2> <p>Lorem ipsum dolor sit amet, consectetuer adipiscing elit, sed diam nonummy nibh euismod tincidunt ut laoreet dolore magna aliquam erat volutpat.</p> <p>Ut wisi enim ad minim veniam, quis nostrud exerci tation ullamcorper suscipit lobortis nisl ut aliquip ex ea commodo consequat.</p> </div>
<p>background-origin: border-box:</p> <div id="example2"> <h2>Lorem Ipsum Dolor</h2> <p>Lorem ipsum dolor sit amet, consectetuer adipiscing elit, sed diam nonummy nibh euismod tincidunt ut laoreet dolore magna aliquam erat volutpat.</p> <p>Ut wisi enim ad minim veniam, quis nostrud exerci tation ullamcorper suscipit lobortis nisl ut aliquip ex ea commodo consequat.</p> </div>
<p>background-origin: content-box:</p> <div id="example3"> <h2>Lorem Ipsum Dolor</h2> <p>Lorem ipsum dolor sit amet, consectetuer adipiscing elit, sed diam nonummy nibh euismod tincidunt ut laoreet dolore magna aliquam erat volutpat.</p> <p>Ut wisi enim ad minim veniam, quis nostrud exerci tation ullamcorper suscipit lobortis nisl ut aliquip ex ea commodo consequat.</p> </div>
</body></html> 2. background-clip 属性
CSS3 background-clip 属性指定背景的绘制面积.
该属性有三个不同的值:
border-box - (默认) 背景是画的边框外边缘 padding-box-背景被显示到填充物的外缘。content-box - 背景是画在内容框内
下面举例演示了background-clip属性:
#example1 { border: 10px dotted black; padding: 35px; background: yellow; background-clip: content-box;}
四、总结
本文主要介绍了CSS背景,通过CSS实现多背景显示,自定义某一些尺寸显示格式,background-origin等多个属性的应用,丰富的案例帮助大家更好的理解。
希望大家自己去尝试一下,实现的时候,总会有各种各样的问题,切勿眼高手低,勤动手,才可以理解的更加深刻。
图片新闻
最新活动更多
-
5月10日立即下载>> 【是德科技】精选《汽车 SerDes 发射机测试》白皮书
-
5月16日火热报名>>> OFweek锂电/半导体行业数字化转型在线研讨会
-
5月22日立即报名>>> OFweek 2024新周期显示技术趋势研讨会
-
5月28日立即观看>> 【在线研讨会】Ansys镜头点胶可靠性技术及方案
-
5月31日立即报名>> 【线下论坛】新唐科技2024未来创新峰会
-
6月18日立即报名>> 【线下会议】OFweek 2024(第九届)物联网产业大会
- 1 拆机实锤!华为Pura70使用新芯片,推测为7nm,性能如何?
- 2 华为P70系列即将强势来袭,能否再次复制华为Mate60系列的辉煌?
- 3 中国芯片基地诞生:一年产量1055亿颗,占全国30%,三省共占67%
- 4 华为麒麟9010、苹果A17、高通8Gen3对比,差距有多大?
- 5 避免内卷?中国大陆4大芯片代工厂,产能、营收、优势介绍
- 6 形势严峻!暴增256%,中国还在疯狂进口ASML光刻机
- 7 过去14个月,山东从荷兰进口了12台光刻机
- 8 华为Pura70又打脸了?美国商务部长:华为芯片没那么先进
- 9 MTK和Intel联手,投资RISC-V芯片新贵谋发展?
- 10 华为Pura70证明:我们7nm已没问题,接下来是5nm、3nm
发表评论
请输入评论内容...
请输入评论/评论长度6~500个字
暂无评论
暂无评论