我试图用内联背景颜色覆盖 CSS 中预定义的背景图像,认为它实际上会覆盖,但看起来并没有。我怎样才能做到这一点?
.section {
position: relative;
top: 0;
left: 0;
width: 250px;
height: 250px;
background-image: url("https://static.pexels.com/photos/36487/above-adventure-aerial-air.jpg");
background-size: cover;
}
<div class="section" style="background-color: rgb(250, 40, 38)">
</div>
谢谢。
最佳答案
https://www.w3.org/TR/css3-background/#the-background-color
This property sets the background color of an element. The color is drawn behind any background images.
关于javascript - 为什么 background-image 在 CSS 中比内联 background-color 具有更高的优先级?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41885070/