css - 背景颜色,顶部有不透明图像

标签 css image colors background transparent

我想使用背景颜色以及透明(或不透明)的背景图像。这可能吗?

我试过使用 div 命令,但可能做错了。我能看到的唯一不透明命令是在 CSS 中,但是如何将其专门链接到背景图像,而不仅仅是正文内容?

最佳答案

也许这就是您要查找的内容(运行代码段以查看):

.stack{
  height: 200px;
  width: 200px;
  background-color: #ddd;
  position:relative;
}

.layer {
  position: absolute; 
  top: 0; 
  left: 0;
  height: 100%;
  width: 100%;
  background-image: url('http://design.ubuntu.com/wp-content/uploads/ubuntu-logo32.png');
}

.base{
  filter: opacity(.3);
  -webkit-filter: opacity(.3);
}

.offset{
  margin-top: 20px;
}
<div class="stack">
  <div class="layer base">
  </div>
  <div class="layer offset">
  </div>
</div>

我在顶层添加了边距,以便您看到在另一层下面有两层(基础层)。如果您删除边距,您应该会看到图像完美对齐。

关于css - 背景颜色,顶部有不透明图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41978140/

相关文章:

image - Qt/QML。一种无负载学习图像尺寸的方法

python - tkinter:更改特定菜单项的前景色

Java Robot类鼠标移动到特定像素的位置(鼠标单击颜色)

python - 来自 AWS Elastic Beanstalk 的 Mime 类型错误

html - 如何为具有相同分辨率的不同设备提供相同网址的不同 View ?

css - 在 CSS3 和 WebKit 中使用列计数的列的额外边距

html - 使用 CSS 在网页中心对齐照片(带标题)

css - 基金会的网格系统 : Hiding an element when screen becomes smaller doesn't work

css - 具有响应性的 CSS 中的图像优先

css - 狮身人面像 : how to set the color of visited links (sphinx_rtd_theme)