如何让div元素与其父元素具有相同的背景图像?

时间:2014-02-18 01:05:39

标签: html css

如何让子div元素具有与父元素相同的背景纹理?背景是小方块的纹理,但是当我尝试给子元素提供与父元素相同的背景时,方块不会排列。有什么想法吗?

HTML:

<!DOCTYPE html>
<html>
<head>
<style>
.parent{
  width:500px;
  height:500px;
  background-image:url('wallpaper324845.jpg')
}
.child{
width:200px;
height:200px;  
/*how to get the same background-image*/
}
</style>
</head>
<body>
<div class="parent">
  <div class="child">

  </div>
</div>
</body>
</html>

2 个答案:

答案 0 :(得分:2)

不要给孩子分配背景。

答案 1 :(得分:2)

background-image: inherit;这样做吗?

background: transparent;