网页的某些装饰可以通过背景图片来渲染,使得网页更加美观,CSS设置背景图片,不仅仅是大小,还有位置,放大方式,透明化之类。都是必备的CSS技能。层叠样式表(英文全称:Cascading Style Sheets)是一种用来表现HTML(标准通用标记语言的一个应用)或XML(标准通用标记语言的一个子集)等文件样式的计算机语言。演示实例如下:
工具/原料
1
浏览器
2
文本编辑器
方法/步骤
1
对于背景图片的导入,可以选择background 或者background-image格式如下body{backgroud:url('url')}body{backgroud-image:url('url')}background: url(http://exp.bdstatic.com/static/common-jquery/widget/search-box/img/logo_83ae7e2.png);
3background_picture
由上个例子我们可以发现,其实可以对背景图片进行位置的定位:background-position:top left,;top righ;,bottom right;bottom left;代码如下:
Modify
background-position
right top and left top
4background_picture
所以可以对,background picture设置大小,首先设置窗口大小:格式:width:numbers unit (px)height:numbers unit (px)实例代码:
Modify
background-size
width and height
5background_picture
我们发现对background-size的设置有cover、contain等参数。cover:顾名思义为覆盖,即将背景图片等比缩放以填满整个容器;contain:容纳,即将背景图片等比缩放至某一边紧贴容器边缘为止。实例代码:
Modify
background-size
width and height
6background_picture
对图片进行放大与缩小使用background-size:percentage代码实例:
Modify
background-size
格式如下:background-position : length || length background-position : position || position background-position-x : length | left | center | right background-position-y : length | top | center | bottom注意事项
2
对背景图片大小的设置可通过多种途径实现
上一篇:threejs如何画线
下一篇:HTML DOM 事件的使用技巧