在css的div中设置背景图片后背景图片下移如何解决

html-css014

在css的div中设置背景图片后背景图片下移如何解决,第1张

background:url(images/loginbackground.png)top no-repeat 0px 10px

等同与

background:url(images/loginbackground.png)top no-repeat

background-position: 0px 10px//水平方向(以左上角为原点,x方向)移动 0像素,垂直方向(y轴方向)即向下以动 10 像素

***注意:0px 不能省略,否则默认为x方向移动的距离。也可以设置为百分比值。

修改后:

你需要用到background-position这个属性,用以规定背景图片的位置。让图片居中偏下的代码为:

background-positon:center bottom 或 background-positon:bottom

全部的位置代码如下:

background-position: left 代表背景图横向(X轴)靠左,纵向(Y轴)居中。(9点钟位置)

background-position: right 代表背景图横向(X轴)靠右,纵向(Y轴)居中。(3点钟位置)

background-position: top 代表背景图横向(X轴)居中,纵向(Y轴)靠上。(12点钟位置)

background-position: bottom 代表背景图横向(X轴)居中,纵向(Y轴)靠下。(6点钟位置)

background-position: center 代表背景图横向(X轴)居中,纵向(Y轴)居中。(绝对居中)

background-position: left top 代表背景图横向(X轴)靠左,纵向(Y轴)靠上。(10点钟位置)

background-position: left bottom 代表背景图横向(X轴)靠左,纵向(Y轴)靠下。(7点钟位置)

background-position: right top 代表背景图横向(X轴)靠右,纵向(Y轴)靠上。(1点钟位置)

background-position: right bottom 代表背景图横向(X轴)靠右,纵向(Y轴)靠下。(5点钟位置)

需要准备的材料分别有:电脑、浏览器、html编辑器。

1、首先,打开html编辑器,新建html文件,例如:index.html。

2、在index.html中的<style>标签中,输入css代码:body {background: url(image.jpg) no-repeatbackground-size: 300px}。

3、浏览器运行index.html页面,此时背景图片成功用css等比例缩小到了300px宽度的大小。