html - 将图像作为水印添加到响应式内容

标签 html css twitter-bootstrap

我有如下页面内容。当产品库存不可用时,我需要添加一张图像作为水印,说明缺货。我怎样才能做到这一点?请参见示例图像。此外,此框大小不固定。它是动态的。因为在移动设备中,盒子的尺寸更宽并且一个接一个地堆叠(不是排成一排)。所以在那种情况下我不能使用绝对位置。 enter image description here

<div class="col-sm-12">
     <div class="row">
        description about product
     </div>
     <div class="row">
        Select how many you want.
     </div>
     <div class="row">
         Out of Stock

     </div>
</div>

最佳答案

您可以使用伪元素添加“缺货”图像。

html:

<div class="box1 outofstock">
</div>
<div class="box2 outofstock">
</div>
<div class="box3 outofstock">
</div>
<div class="box4 outofstock">
</div>

CSS:

div.outofstock:after {
  background: transparent url(http://www.computingsystem.in/img/outofstock.png) no-repeat center;
  background-size: contain;
  content: " ";
  display: block;
  position: absolute;
  height: 100%;
  width: 100%;
}

div {
  display: inline-block;
  width: 100px;
  height: 75px;
  background-color: #800;
  position: relative;
}
.box2 {
  width: 200px;
  height: 100px;
}
.box3 {
  width: 250px;
  height: 100px;
}
.box4 {
  width: 500px;
  height: 300px;
}

https://jsfiddle.net/ufktcas1/

我制作了不同尺寸的盒子,因此您可以根据尺寸查看它们的外观。

此外,您还可以选择不使用图像: https://jsfiddle.net/ufktcas1/1/

在您的情况下,应将 .outofstock 类添加到 col-sm-12 元素。但是 col-sm-12 必须有 position: relative; 才能工作。

关于html - 将图像作为水印添加到响应式内容,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35079045/

相关文章:

javascript - 如何在从字符串构建的 HTML 中设置事件?

jquery - 允许 <BR> 或新行到 jquery 工具提示

java - 不允许加载本地资源 : in chrome tomcat

javascript - 如何在react-data-grid中的rowselection中禁用行的复选框

css - Sass @extend 行为类似于 LESS 和 @import

javascript - 根据用户输入扩展数量 Html 输入宽度?

html - CSS - 阻止 :hover during animation?

html - Span 标签在 Drupal Bootstrap 子主题中显示为文本

javascript - 如何让我的提交按钮启动 JQ 功能?

html - 我怎样才能删除这个间距?