简体   繁体   English

如何在背景颜色上添加图像?

[英]How do I add an image over background colour?

How do I add an image over background colour?如何在背景颜色上添加图像? I want the image the to at the bottom of the div.我希望图像位于 div 的底部。 I tried it with the code below but it doesn't seem to work for me.我用下面的代码尝试了它,但它似乎对我不起作用。 See code below:请参见下面的代码:

 .teal { text-align: center; padding: 40px; background-color: #2dd5c4; background-image: url("https://www.w3schools.com/html/pic_trulli.jpg"); background-repeat: no-repeat; background-position: bottom; }
 <div class="teal"> <h3>Lorem ipsum dolor sit amet</h3> <p>Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Aenean commodo l. igula eget dolor. Aenean massa. <br /> <button> Call to action</button></p> </div>

Maybe try add the !important tag at the end of the background-image也许尝试在背景图像的末尾添加 !important 标签

background-image: url(https://www.w3schools.com/html/pic_trulli.jpg) !important;

you can put the image in a different div and put it over your teal class using z-index or having it as a child component to teal class您可以将图像放在不同的 div 中,然后使用 z-index 将其放在您的蓝绿色 class 上,或者将其作为子组件来蓝绿色 class
z-index z-index

    <div class='teal' >
        <div class='image' > </div>
    <div>

u can use this:你可以使用这个:

background-image: url()背景图像:url()

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

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