简体   繁体   中英

Image not visible after applying css background color

I can't able to see the image after applying CSS background color.

HTML page:

<html>
    <head>
    </head>
    <body>
        <div class="heading">
            <h2>
                <span>LUMINO</span>ADMIN
                <img name ="messageicon" alt="Messages" src="<?php echo base_url(); ?>img/closed-envelope-circle.png">
            </h2>
        </div>


    </body>
</html>

CSS page:

.heading{
    background-color: yellow;
    width: 100%;
    height: 10%;
    left: 0;
    top: 0;
}
.heading h2{
    margin-left: 25px;
    padding: 15px;

}
h2{
    color: white;
}
span{
    color: skyblue;
}

SCREENSHOTS:

屏幕截图1

The image should be visible after applying the CSS background color.

Just in case, base_url(); isn't a valid function (if you haven't written one).

you can use $_SERVER['REQUEST_URI'] it gave you the whole link from your Website back in form of an String. In that case you can use the substr to cut the sting in your form you like.

Here is my Examlpe of your code:

<html>
    <head>
    </head>
    <body>
        <div class="heading">
            <h2>
                <span>LUMINO</span>ADMIN
                <img name ="messageicon" alt="Messages" src="<?php echo($_SERVER['REQUEST_URI']); ?>img/closed-envelope-circle.png">
            </h2>
        </div>
    </body>
</html>

If you want to know more about base urls take a look here

Enjoy and have fun ;)

--- EDITS: ---

<html>
    <head>
    </head>
    <body>
        <div class="heading">
            <h2>
                <span>LUMINO</span>ADMIN
            </h2>
            <img name ="messageicon" alt="Messages" src="<?php echo($_SERVER['REQUEST_URI']); ?>img/closed-envelope-circle.png" style>
        </div>

        <style>
            .heading {
                background-color: black;
                width: 100%;
                height: 10%;
                left: 0;
                top: 0;
            }
            .heading h2{
                margin-left: 25px;
                padding: 15px;

            }
            h2{
                color: white;
                float: left;
            }
            span{
                color: skyblue;
            }
        </style>
    </body>
</html>

Perhaps this one is better and you can test it with e sperate file so you don't need to change your original.

The images might be having transparent background. In this case it will use the container's background color. Apply a background-color css rule to the img to get a color to your image.

.heading img{
   background-color: white;
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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