html - 更改背景颜色的不透明度,但不更改文本

标签 html css

<分区>

我正在尝试降低背景的不透明度,但让文本的颜色保持不变。

.overview {
  background: gray;
  width: 45%;
  opacity: 0.3;
  margin-left: auto;
  margin-right: auto;
  font-size: large;
  border-radius: 8px;
}

.overview p {
  text-align: center;
  color: white;
}
<div id="overview" class="overview">
  <p>
    Blah blahBlah blahBlah blahBlah blahBlah blahBlah blahBlah blahBlah blahBlah blahBlah blahBlah blah Blah blahBlah blahBlah blahBlah blahBlah blahBlah blahBlah blahBlah blahBlah blahBlah blahBlah blah

  </p>
</div>

但是文本和背景颜色都变暗了

最佳答案

你的 background should be an RGBA color , 应用不透明度是为了 div

background-color:rgba(128,128,128,0.3);

关于html - 更改背景颜色的不透明度,但不更改文本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53325731/

上一篇:CSS calc() 将小数转换为像素

下一篇:javascript - 仅当用户在 200px 和 300px 之间滚动时添加一个类

相关文章:

jquery - 如何在表格中的文本区域右侧对齐按钮?

html - 从 html 属性中删除单引号和双引号,除了 href 和 src 之外的所有属性都没有空格

html - 如何在 overflow hidden 的情况下将缩略图居中?

javascript - 悬停父 div 更改 0 宽度子 div 以匹配包含的图像宽度

javascript - 在单页网站上替换 Div 的内容

html - 悬停在列表元素上的图像

html - 将两个相邻的 div 与左向文本水平对齐

html - 在 Internet Explorer 中重复背景图像

php - 从Mysql ID查询内容

jQuery 隐藏功能不起作用,