背景图片html写法,CSS3背景图片background属性简写/连写

编程入门 行业动态 更新时间:2024-10-24 17:18:34

在开发中背景属性 background 还是很常用的, background 有很多属性,如:

background-color 背景颜色

background-image 背景图像

background-position 背景图像的位置

background-size 背景图片的尺寸

background-repeat 重复背景图像

background-origin 定位区域

background-clip 绘制区域

background-attachment 是否固定或者跟随页面滚动。( scroll :默认值,随页面滚动;fixed 固定,不滚动;inherit继承。)

当然这些属性可以分开写,也可以连写(简写),规则(顺序)如下:background:color img_url repeat attachment position / size

颜色 图片地址 重复 是否固定 位置 / 尺寸

示例:background:#F00 url('img/images.png') no-repeat fixed center / cover

红色背景,不重复,固定背景,居中,短边填充。

图像位置和尺寸用 / 隔开,前面是 background-position ,后面是 background-size 。

其中 background-position 的写法注意:语义描述时是 top left ,数值描述时是 x-pos y-pos ,两种顺序相反。 background-size 的写法是:width height 。

这样分开写会更好理解一些:background:#F00 url('img/images.png') no-repeat fixed top left / 100% auto

靠左上,宽度 100% ,高度自适应。

更多推荐

背景图片,简写,写法,属性,html

本文发布于:2023-05-25 13:40:56,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/306103.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:背景图片   简写   写法   属性   html

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!