【问题标题】:Set background image with transparent color and also make the height of the image adapt to the content设置透明色背景图片,同时使图片高度适应内容
【发布时间】:2017-11-07 22:55:50
【问题描述】:
.about {
  width: 100%;
  height: 300px;
  background-color: rgba(0,0,0,0.55);
}

我正在尝试为图像设置透明度为 55% 的黑色。 另外我需要图像的高度与内容一样长。 内容将位于某些列上,但在平板电脑和移动设备分辨率下,所有列将依次排列,因此内容将不适合图像。

我还需要透明度来只影响图像而不影响文本。

实现这一目标的最佳方法是什么?

这是我的小提琴:fiddle

【问题讨论】:

标签: html css responsive


【解决方案1】:
.about {
  width: 100%;
  height: 100%;
  position:relative;
}
.about:after{
   content : "";
    display: block;
    position: absolute;
    top: 0;
    left: 0;
    background:url('http://i.imgur.com/tENv1w4.jpg') no-repeat center center; 
    width: 100%;
    height: 100%;
    opacity : 0.55;
    z-index: -1;
}

.text {
  color: #fff;
  font-size: 22px;
  text-align: center;
}

检查这个小提琴以获得您的解决方案。

https://jsfiddle.net/n5qfa/89/

【讨论】:

猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2011-09-24
  • 2013-08-16
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多