宝塔服务器面板,一键全能部署及管理,送你10850元礼包,点我领取

在给网页加背景图时会遇到:图片过大,只能显示出部分,不能完整的显示出来,实现不了设计的效果,怎么办?

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>无标题文档</title>
<style type="text/css">
body{ background:url(images/hi-wifi-bg.jpg) no-repeat center center; background-size:100% 100%; }
</style>
</head>

<body>
<p style=" 100px; height:1000px;background:#000; opacity:0.5;">
</p>
</html>
</body>
</html>

View Code

background:url(images/hi-wifi-bg.jpg) no-repeat center center; background-size:100% 100%; 

背景图片的定位background-position设为center center(x,y)

background-size规定背景图像的尺寸,默认值是auto,

语法

background-size: length|percentage|cover|contain;
描述  
length

设置背景图像的高度和宽度。

第一个值设置宽度,第二个值设置高度。

如果只设置一个值,则第二个值会被设置为 “auto”。

 
percentage

以父元素的百分比来设置背景图像的宽度和高度。

第一个值设置宽度,第二个值设置高度。

如果只设置一个值,则第二个值会被设置为 “auto”。

 
cover

把背景图像扩展至足够大,以使背景图像完全覆盖背景区域。

背景图像的某些部分也许无法显示在背景定位区域中。

 
contain 把图像图像扩展至最大尺寸,以使其宽度和高度完全适应内容区域。  

在这些属性中多试几次