.
3ss.cn

怎么样设置html的背景图片的位置

设置html的背景图片的位置的方法是,给背景图片添加background-position属性,并且修改合适的属性值就可以了,例如【background-position:center;】。

如果我们想要在html代码中移动下背景图片的位置,其实可以借助于background-position属性。可能不少同学还不知道这个属性,下面我们来介绍下这个属性。

background-position属性是用来设置背景图像的起始位置的。

它的常用属性值有以下这些:

left top

left center

left bottom

right top

代码示例:

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8"> 
<title>互联学术(php.cn)</title> 
<style>
body
{ 
	background-image:url('smiley.gif');
	background-repeat:no-repeat;
	background-attachment:fixed;
	background-position:center; 
}
</style>
</head>

<body>
<p><b>注意:</b>该属性工作在 Firefox 和 Opera, background-attachment 属性会被设置为 "fixed"。</p>
</body>
</html>

大家可以将上面的代码复制到本地,运行看下效果。

赞(0)
未经允许不得转载:互联学术 » 怎么样设置html的背景图片的位置

评论 抢沙发