css background-size属性怎么用
程序员文章站
2022-03-16 15:31:44
...
css background-size属性可以设置背景图片的大小。语法:background-size: length|percentage|cover|contain;通过长度值或百分比来设置图片大小,或者通过cover和contain来对图片进行伸缩设置。
css background-size属性怎么用?
作用:规定背景图像的尺寸。
语法:
background-size: length|percentage|cover|contain;
说明:
length 设置背景图像的高度和宽度。第一个值设置宽度,第二个值设置高度。如果只设置一个值,则第二个值会被设置为 "auto"。percentage 以父元素的百分比来设置背景图像的宽度和高度。
第一个值设置宽度,第二个值设置高度。如果只设置一个值,则第二个值会被设置为 "auto"。cover 把背景图像扩展至足够大,以使背景图像完全覆盖背景区域。背景图像的某些部分也许无法显示在背景定位区域中。contain 把图像图像扩展至最大尺寸,以使其宽度和高度完全适应内容区域。
注释:IE9+、Firefox 4+、Opera、Chrome 以及 Safari 5+ 支持 background-size 属性。
css background-size属性使用示例
<!DOCTYPE html> <html> <head> <style> body { background:url('https://img.php.cn/upload/article/000/005/656/5af270fd37755429.jpg'); background-size:100px 63px; -moz-background-size:100px 63px; /* 老版本的 Firefox */ background-repeat:no-repeat; padding-top:80px; } </style> </head> <body> <p>上面是缩小的背景图片。</p> <p>原始图片:<img src="https://img.php.cn/upload/article/000/005/656/5af270fd37755429.jpg" alt="Flowers"></p> </body> </html>
效果输出:
以上就是css background-size属性怎么用的详细内容,更多请关注其它相关文章!
推荐阅读
-
ACDsee怎么用?acdsee做图像属性的教程
-
VS2019怎么设置CSS的默认属性?
-
css设置全屏背景图,background-size 属性
-
CSS3属性background-size使用指南
-
2个属性用CSS实现图片自适应浏览器
-
怎么用css属性屏蔽鼠标事件(鼠标点击可穿透上层元素)
-
关于用图片做无序列表的项目符号,我做出来怎么是这个样子?_html/css_WEB-ITnose
-
css background-size 属性_html/css_WEB-ITnose
-
怎么用dreamweaver做一个可以换肤的界面_html/css_WEB-ITnose
-
发现一个特效会让你有意思,有人知道这个用css可以做出来吗,怎么做?_html/css_WEB-ITnose