- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
问题是 rgba
透明度。我应该改变它的背景并使其透明。但是,它只是改变了背景颜色,并没有使其透明。
我经常遇到这个问题,有时有效,有时无效。
我试图弄清楚为什么有时它不起作用,即使我的编码方式与其他时候完全一样。
我还看到了一些建议,比如 rgba
和 ()
之间的间距、alpha 的范围等等。但它们都不是很有帮助。
然后我看到了下面的建议。 (不记得出处了)“rgba 不影响子元素”。我几乎不记得了,所以我可能是错的,因为英语不是我的第一语言,所以我听不懂。
我有以下问题
1.> 如果陈述正确,请解释一下是什么意思?
2.> 附上的代码就是这个问题的例子。背景已更改但不透明。所以,请让我知道问题是否出在 child 和 parent 元素上。
3.> 让我知道您在阅读下面我的代码时注意到的任何事情。
* {
margin: 0;
padding: 0;
}
#top {
background: url("./img/vbs/vbs4.png") no-repeat center center fixed;
background-size: cover;
width: 100vw;
height: 100vh;
}
.outer {
background: rgba(100, 100, 50, .5);
width: 100vw;
height: 100vh;
display: flex;
}
.inner {
background: white;
width: 80vw;
height: 70vh;
margin: auto;
display: flex;
border-radius: 20%;
}
.inner>h1 {
margin: auto;
font-size: 3rem;
}
<div id="top"></div>
<div class="outer">
<div class="inner">
<h1>This is the title</h1>
</div>
</div>
<div class="outer">
<div class="inner">
<h1>This is the title</h1>
</div>
</div>
最佳答案
在上面的示例代码中,元素 .outer
是唯一具有 rgba()
样式的元素,因此元素只有 alpha/opacity/透明度应用于它。 .outer
是 .inner
的父元素,您已将未应用透明度的子元素与应用了透明样式的元素放在一起。你还提到有人说间距可能是问题,但不是,即使你在它之间放了一个长的 2 个空格或没有空格,它也不会影响 css 代码。您提到的短语“rgba 不影响子元素”是正确的,就像我说的唯一具有 rgba
的元素是 .outer
。这就像在玻璃上画画,然后你把一个物体放到玻璃上,但物体不是玻璃。所以玻璃只有透明的行为/特性。
这是您附加的修复代码,只是向 .inner
元素添加了一个 opacity
* {
margin: 0;
padding: 0;
}
#top {
background: url("./img/vbs/vbs4.png") no-repeat center center fixed;
background-size: cover;
width: 100vw;
height: 100vh;
}
.outer {
background: rgba(100, 100, 50, .5);
width: 100vw;
height: 100vh;
display: flex;
}
.inner {
background: white;
width: 80vw;
height: 70vh;
margin: auto;
display: flex;
border-radius: 20%;
/* opacity applied to the child outer (inner) */
opacity: 0.5;
}
.inner>h1 {
margin: auto;
font-size: 3rem;
}
<div id="top"></div>
<div class="outer">
<div class="inner">
<h1>This is the title</h1>
</div>
</div>
<div class="outer">
<div class="inner">
<h1>This is the title</h1>
</div>
</div>
关于html - rgba 不让背景色透明,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57364946/
更新的(未保存的)文本行有明亮的粉红色(#ffc286)背景色,更改和保存的文本行有明亮的绿色(#b5ffb5)。任何颜色样式的背景都是相同的。 我在Style Configurator中找不到它(我
这个问题在这里已经有了答案: 9年前关闭。 Possible Duplicate: Change background color of UI elements in eclipse IDE 你们可能
在构建布局时,我注意到 selectableItemBackground 的背景颜色与 UI 其余部分的背景颜色不匹配。为了缓解这种情况,我想导入 {android_sdk}/platforms/{p
我正在努力让 UITableView 后面的颜色成为我想要的灰色。 UITableView 的背景似乎工作正常,但其后面的区域仍然保持白色? 我的观点到此结束。其中只有一个单元格,并且它不是裁剪后的图
我有一个 CALayer 背景使用: CAGradientLayer *bgLayer = [BackgroundLayer blueGradient]; bgLayer.frame = self.v
我有一个水平菜单。我想在菜单周围有一个边框(不是整行,只有空间菜单被覆盖)。当我在 ul 上放置边框时,它覆盖了整行,当我在 li 上放置边框时,它在菜单项之间也有边框。
我正在使用 bootstrap 3.0,以下是我的 HTML 代码,我遇到了背景颜色问题。 HTML代码 Collection
我遇到了一个示例问题,它应该在 JQuery 中的悬停事件上更改背景颜色。(符合 .css("background-color","rgba(78, 175, 212, 0.75)");) 所有其他更
我正在尝试为我的 View 页面提供背景色,但当我想要所有内容时,它总是只给我 3/4 的页面浅蓝色。 (见截图)任何人都可以帮助我吗?非常感谢 这是我使用的CSS代码:背景.css .contain
我正在尝试为 www.livejournal.com 上的所有页面制作时尚的用户样式。我想为文本设置样式并选择具有特定背景颜色的类型输入框,但背景颜色并未在所有输入框上设置,即使 color 已设置。
我正在学习 Bootstrap。我在做一个主题。但是在页面底部,我在页脚标签处添加了页脚背景颜色,它没有改变。并且还注意到 footer 标签的类属性没有显示在 Firebug 检查元素中。出了什么问
我的 CSS 文件包含我的网页显示,网页比屏幕小(如果你知道我的意思)我试图用背景颜色填充容器的外部,但它不起作用。有人可以帮忙吗?这是我的 CSS #container { wid
我使用的是最新版本的 matlab。我正在使用带有 jet 颜色图的 imagesc 命令绘制矩阵。矩阵的背景值为零,在图像中绘制为颜色条上的最低颜色,即深蓝色。有没有办法使背景零值绘制为白色? 谢谢
我一直在研究网站以弄清楚它们是如何工作的。通过下载它们并在 dream weaver cs6 中打开。但是当我在浏览器中打开下载的 html 文件时,除了绿色背景被默认的白色背景替换之外,一切都显示正
我有两个相互重叠的文本框。第一个文本框“TextBox1”由用户输入定义。第二个“TextBox2”由自动完成功能填充。我的目标是让第一个文本框的背景仅对于已键入的文本为白色,以便生成的“TextBo
我正在尝试更改(https://developer.android.com/samples/SlidingTabsBasic/src/com.example.android.common/view/S
我有以下 RelativeLayout 但我想改进它。 (做一个漂亮的设计) .
我有一个 ImageButton,其背景图像具有一定的透明度。默认情况下,按钮在透明像素所在的位置获得灰色背景 - 由于 Holo.Light 主题。我尝试通过 setBackgroundColor(
我有一个 UITableViewController,我正在尝试自定义样式。我已经完成了 95%,但无法从单元格背景中移除奇怪的阴影。我在这个屏幕截图中突出显示了我要删除的内容: 为了尝试解决这个问题
我正在循环中以编程方式创建一些 UIButton,但我在设置按钮的背景颜色时遇到了一些问题。 按钮的颜色始终显示为白色。但是我在背景颜色中只使用 2 种颜色时效果很好。例如:红色:255 绿色:0 蓝
我是一名优秀的程序员,十分优秀!