【问题标题】:adding a black overlay to an image that is not a background image wordpress posts plugin向不是背景图像的图像添加黑色叠加层 wordpress 帖子插件
【发布时间】:2017-04-22 07:13:32
【问题描述】:

我想为不是背景图像的图像添加黑色叠加层。

我已经尝试使用以下代码但不起作用,

background-color: black, opacity: 0.5;

我也不能在它上面放置另一个 div,因为它是一个插件,有时需要一些时间来加载

这是当前的 css 代码

.flexslider .slides img {
max-height: 700px;
padding-bottom: 0px;
width: 100%;
background-color: black;
margin-top: -2%;
  background-color: rgba(0, 0, 0, 0.5) !important;

【问题讨论】:

  • .flexslider .slides { 背景颜色:rgba(0, 0, 0, 0.5) !important;将背景颜色添加到包含图像而不是图像本身的容器中
  • 请添加网址以便更好地理解
  • @VasimVanzara 我本地主机上的站点
  • @tea93 好的....

标签: wordpress plugins tags posts


【解决方案1】:

你应该使用伪元素“:after”:

伪元素不能用在img上,必须用在父div上

.flexslider .slides{
  //blablabla
  display : inline-block;
  position : relative;
}

.flexslider .slides:after{
  position : absolute;
  content : " ";
  top : 0;
  left : 0;
  height : 100%;
  width : 100%;
  background-color : black;
  opacity : 0.5;
}

【讨论】:

猜你喜欢
  • 1970-01-01
  • 2019-01-05
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2019-07-29
  • 2020-08-13
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多