background-repat背景重复

珠峰HTML|CSS精讲视频 admin 425浏览

background-repat背景重复

  • 指定如何重复背景图像,默认情况下,重复background-image的垂直和水平方向.
  • repat 背景图像将向垂直和水平方向重复,这是默认
  • repat-x只有水平位置会重复背景图像
  • repat-y只有垂直位置会重复背景图像
  • no-repat代表background-image不会重复
  • inherit 指定background-repat属性设置应该从父元素继承

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>background-repat背景重复</title>
<style type="text/css">
.logo{
width: 300px;
height: 300px;
background-image: url(http://www.zhufengpeixun.cn/skin/20142/img/logo1.png);
background-repeat: repeat-x;
}
.nav{
width: 100%;
height: 42px;
/*拆分的写法*/
/* background-image: url(http://www.zhufengpeixun.cn/skin/20142/img/navbj.png);
background-repeat: repeat-x; */
/*复合写法:简写*/
background: url(http://www.zhufengpeixun.cn/skin/20142/img/navbj.png) repeat-x;
}
</style>
</head>
<body>
<div class="logo"></div>
<div class="nav"></div>
</body>
</html>

background-repat:背景重复(平铺的方式);默认值repat(x/y轴同时平铺);no-repat不平铺(不重复)repat-x平铺方式:x轴平铺

补充:由于导航nav的背景正好42px,所以即便我们不写repat-x,它也只有X轴方向的平铺,因为Y轴没有多的高度去平铺;但是如果height和navbj的高度不相等话,我们不写background-repat会出现除了X轴平铺之外,也会看到Y轴平铺效果,所以我们最好在background图片的后面紧跟指明平铺的方式!

background-color/background-iamge可简写为background,background-repat不能简写为background

转载请注明:大灰牛博客 » background-repat背景重复