【问题标题】:How can I overlay text on multiple images with different sizes? css如何在多个不同大小的图像上叠加文本? css
【发布时间】:2016-11-19 22:14:35
【问题描述】:

我有一位客户希望在她所有已售出的图片上添加一个已售出的文字,这些图片位于每张图片的左下角。我已经完成了实现,但问题是某些图像的大小不同。无论图像大小如何,是否有一种“一类适合所有”类型的 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>

【问题讨论】:

  • 使用bottom 属性而不是top。如果要将文本定位在所有图像的同一位置,请使用 px 单位而不是百分比。

标签: html css overlay image-size


【解决方案1】:

我将红色的 Sold 横幅放置在左下角,并将图像的大小调整为 100%,以便它始终填充其列/响应容器:

.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>

【讨论】:

  • 非常感谢 Nathaniel,它就像一个魅力!我整天都在寻找这个答案,什么也没有。我很高兴这里的人们愿意提供帮助。
猜你喜欢
  • 1970-01-01
  • 2022-01-20
  • 1970-01-01
  • 1970-01-01
  • 2017-05-07
  • 1970-01-01
  • 1970-01-01
  • 2014-12-22
  • 1970-01-01
相关资源
最近更新 更多