如何在多个不同大小的图像上叠加文字? css

How can I overlay text on multiple images with different sizes? css

我有一个客户想要在她所有已售出的图片上方添​​加已售出的文字,这些图片位于每张图片的左下角。我已经完成了实施,但问题是有些图像的大小不同。是否有 "one class fits all" 类型的 css 我可以使用它来正确定位文本而不考虑图像的大小?

代码:

.sold-overlay {
  position: absolute; 
  top: 80%; 
  left: 59%; 
  width: 25%;
  border: 1px solid #e60000;
  color: white;
  font-size: 50%;
  background-color: red;
}
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet"/>
<div class="container">
  <div class="row">
    <div class="col-lg-8 col-lg-offset-2">
      <div class="modal-body">
        <h2>I Am Travon Martin</h2>                          
        <img class="img-responsive img-centered" src="img/portfolio/sold/img-6847.jpg" alt="">
        <h2 class="sold-overlay">Sold</h2>
        <p>I'm sorry, this artwork has been sold to a happy customer.</p>                           
        <button type="button" class="btn btn-primary" data-dismiss="modal"><i class="fa fa-times"></i> Close Project</button>
      </div>
    </div>
  </div>
</div>

我将红色的“已售出”横幅放在左下角,并将图片的大小调整为 100%,这样它就会始终填满 column/responsive 容器:

.sold-overlay {
position: absolute; 
bottom: 0; 
left: 0; 
width: 25%;
border: 1px solid #e60000;
color: white;
font-size: 50%;
background-color: red;
}

.relative {
position: relative;  
}

.relative img {
  display: block;
  width: 100%;
  }
<div class="container">
                <div class="row">
                    <div class="col-lg-8 col-lg-offset-2">
                        <div class="modal-body">
                            <h2>I Am Travon Martin</h2>                      
                          <div class="relative">
                            <img class="img-responsive img-centered" src="http://placehold.it/200x100" alt="">
                            <div class="sold-overlay"><h2>Sold</h2></div>
                            </div>
                            
                            <p>I'm sorry, this artwork has been sold to a happy customer.</p>                           
                           
                        </div>
                       <button type="button" class="btn btn-primary" data-dismiss="modal"><i class="fa fa-times"></i> Close Project</button>
                    </div>
                </div>
            </div>