我不想在 CSS 中从父级继承子级不透明度 [英] I do not want to inherit the child opacity from the parent in CSS

查看:23
本文介绍了我不想在 CSS 中从父级继承子级不透明度的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我不想在 CSS 中从父级继承子级不透明度.

I do not want to inherit the child opacity from the parent in CSS.

我有一个 div,它是父级,我在第一个 div 内有另一个 div,它是子级.

I have one div which is the parent, and I have another div inside the first div which is the child.

我想在父 div 中设置 opacity 属性,但我不希望子 div 继承 opacity 属性.

I want to set the opacity property in the parent div, but I don't want the child div to inherit the opacity property.

我该怎么做?

推荐答案

不要使用不透明度,而是使用 rgba 设置背景颜色,其中a"是透明度级别.

Instead of using opacity, set a background-color with rgba, where 'a' is the level of transparency.

所以代替:

background-color: rgb(0,0,255); opacity: 0.5;

使用

background-color: rgba(0,0,255,0.5);

这篇关于我不想在 CSS 中从父级继承子级不透明度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆