简体   繁体   English

线性渐变背景会覆盖其他元素(例如img或文本)

[英]linear-gradient background overwrites other elements (such as img or text)

I am writing code with CSS and Bootstrap 4. I have made a background of gradient, but when I start adding other elements, such as images or text they appear to be basically invisible because of the gradient being on top of them. 我正在使用CSS和Bootstrap 4编写代码。我已经创建了渐变背景,但是当我开始添加其他元素(例如图像或文本)时,由于渐变位于它们之上,因此它们看起来基本上是不可见的。 Is there a solution? 有解决方案吗?

 .background{ background-image: linear-gradient(to top, black, white); opacity: 0.3; } 
 <html> <div class="background"> <div class = "row"> <img src"https://devfest.gdg-taipei.org/images/logos/google.svg"> </div> </div> </html> 

Try something like this: 尝试这样的事情:

<div class="background"> 
    <div class="background-curtain"></div>
    <div class = "row"> <!--First Section-->
        <img src="img.png"> 
    </div> 
    <div class = "row"> <!--Second Section-->
        <p>Hello</p> 
    </div> 
</div> 

CSS: CSS:

.background{ 
        position: relative;
    }
    .background-curtain{
        position: absolute;
        width: 100%;
        height: 100%;
        background-image: linear-gradient(to top, black, white);opacity: 0.3;
        z-index: -100;
    }

 .background{ opacity: 0.3; } .row{ position:absolute; background-image: linear-gradient(to top, black, white); z-index:0; width:100%; height:100%; top:0; left:0; } .image{ position:relative; z-index:1; } 
 <html> <div class="background"> <div class = "row"> </div> <div class="image"> <img src="https://devfest.gdg-taipei.org/images/logos/google.svg"> </div> </div> </html> 

As i understand your question, may be this will help you 据我了解您的问题,也许这会帮助您

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM