css - CSS Opacity atop Image Overlay
问题描述
I am seeking help correcting the opacity on a class. Please pardon my not having shown the work for the many approaches I have tried.
Following is a demo on codepen: Codepen Demo
.intro .uk-overlay-primary {
opacity: 0.5;
}
.intro .intro-title {
opacity: 1;
}
The 'intro-title' class is inheriting the opacity of the 'ul-overlay' class. How can I resolve this, forcing the 'intro-title' opacity to be 1, atop of the overlay class?
解决方案
As I commented this is somehow similar to this post. For the solution, you can try this. I changed the structure if its okay to you and made the overlay position: absolute
.intro .uk-overlay-primary {
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
background-image: linear-gradient(326deg, #80009F 0%, #643097 98%);
opacity: 0.5;
}
There are other ways to get this result but I choose to use this approach to have minor changes on your code.
For better understanding, as mentioned in MDN web docs
opacity applies to the element as a whole, including its contents, even though the value is not inherited by child elements. Thus, the element and its children all have the same opacity relative to the element's background, even if they have different opacities relative to one another.
推荐阅读
- iphone - Aframe mobile 无法检测设备的方向
- python - 如何在 PyCharm 中将所有相对导入转换为绝对导入?
- php - 如何在没有引号的情况下获得数组结果
- android - 为什么使用隐式意图时不需要互联网许可?
- angular - 仅来自角度 7 的 PUT 请求出现“被 CORS 策略阻止”错误
- javascript - Discord.JS 中的轮询命令有问题。你如何解决这个问题?
- excel - RangetoHTML 子程序突然停止工作
- c# - 有没有办法直接从 C# 应用程序将文件写入 Azure Blob 存储?
- html - 样式标签在 gmail 中不起作用,即使文档另有说明
- excel - 有没有办法在正在创建的文件的 excel 中制作日志?