如何在重叠的div标签上添加文本

Zai*_*ain 1 html css css3

我想添加一个重叠div标签的div标签,并在重叠的div标签上添加一个文本.这是代码..请帮忙.

.center_prod_box{
     border-radius: 15px;
     width:190px;
     height: 260px;
     float:left;
     text-align:center;
     padding:0px 0px 5px; 0; 
     margin:0px 5px 0px 0;
     border:1px #000000 solid;
}

 .product_title{
     background:#cdf895;
     border-radius: 15px;
     textalign:center;
     font-size:12px;
     margin: 7px 5px;
     font-weight:bold;
     color:#ffffff;
     padding:5px 5px 5px 15px;
  }

<div class="center_prod_box">
     <img src="images/offer2.png" style="position:absolute; margin-left:50px; margin-top:-10px;" alt="" border="0" width="60"  height="60" Title="Amul Butter" />
      <div class="offertext" style=" position:absolute; margin-left:0px;">Hello</div>   
          <a href="" Title="Amul Butter">Amul Butter</a>
      </div>
Run Code Online (Sandbox Code Playgroud)

Afz*_*han 6

为此,您可以使用position: absolute;重叠div.并将任何文本添加到该div.

这将是这样的:

<div style="position: relative;">
 <div style="position: absolute;">
  The text to be added, will be written here! :)
 </div>
</div>
Run Code Online (Sandbox Code Playgroud)

你可以使用classid定型它们!在您的图像中,您也position: absolute;用于图像标记.position: relative;如果要将文本放在该图像上,请使用其中一个.或者你可以使用z-index它们,将它们放在另一个上面!

编辑:文本对齐是IE7中的一个错误:http://haslayout.net/css/Text-Align-Bug