我有一个整个页面和另一个内容div的背景图像。我想要的是内容div的背景图像应该是半透明的,以便它下面的一些背景图像(对于整个页面)也应该是可见的。
我也尝试使用图像编辑器来减少我的.png背景文件的不透明度,但它没有显示我下面的背景,而是图像刚刚变亮。使背景图像半透明
使背景图像半透明
回答
使用伪元素
body {
background-image: url(http://lorempixel.com/image_output/nature-q-c-1600-1600-10.jpg);
background-repeat: no-repeat;
background-size: cover;
}
div {
width: 600px;
height: 500px;
position: relative;
}
div::before {
content: '';
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
background-image: url(http://lorempixel.com/image_output/city-q-c-600-500-7.jpg);
opacity: 0.5;
z-index: -1;
}
<div>
<h1>Heading Text</h1>
</div>
但这改变了我不想要的内部文本的不透明度 – Satwik
不,它不。只是伪元素位于文本的顶部。修复了z-index。 –
要透明股利,你可以使用:
.thediv{
background-color: transparent
}
编辑:半透明的:
.thediv{
background:rgba(255,255,255,0.4);
}
默认情况下元素是透明的...... – alesc
HTML
<body>
<div></div>
</body>
CSS
body {
background-image: url(https://static.pexels.com/photos/24419/pexels-photo-24419-large.jpg);
background-repeat: no-repeat;
}
div {
width: 600px;
height: 500px;
background-image: url(https://static.pexels.com/photos/940/sky-sunset-sand-night-large.jpg);
opacity: 0.5;
}
的jsfiddle:https://jsfiddle.net/0jw6c79L/
但这改变了我不想要的内部文本的不透明度 – Satwik
- 1. 使图像背景透明
- 2. 不透明图像的半透明背景
- 3. 半透明面板背景
- 4. 半透明倾斜背景
- 5. Qt css背景半透明
- 6. 透明背景透明图像问题
- 7. 图像背景透明GIMP
- 8. 如何使表单背景半透明?
- 9. 使用PHP png图像透明背景
- 10. 背景图像上的半透明颜色层?
- 11. css半透明背景图像的白色文字背景颜色
- 12. 如何使用透明图像作为透明winform的背景?
- 13. 使图像透明在IE中显示非透明背景
- 14. Div背景半透明,不是内容?
- 15. xlib半透明窗口背景
- 16. 为背景设置常量半透明
- 17. 在android中的半透明webview背景
- 18. 半透明背景上的文字
- 19. 带边框半径的透明背景
- 20. 试图添加背景图像透明度不透明
- 21. 在Photoshop上透明背景图像
- 22. 将背景添加到透明图像
- 23. 透明Jbutton将与背景图像
- 24. 调整图像大小,透明背景?
- 25. 可可NSStatusItem图像 - 不透明背景
- 26. Tkinter - 按钮图像透明背景
- 27. 背景图像,但与不透明css
- 28. HTML/CSS/jQuery:背景图像不透明
- 29. 分组的UITableViewCell透明背景图像
- 30. 透明PNG作为背景图像
你也有'背景color'集?如果是,请将其移除。 – alesc