Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
134 views
in Technique[技术] by (71.8m points)

css - Why is image not appearing in HTML?

So iam a first time HTML and CSS user, and was making a website using a YouTube video, however i reached a stage where i want to show the backround image onto the screen however ive followed the video exactly and it only shows my logo image and not the background image.

This was the youtube video : https://youtu.be/5bMdjkfvONE I got up to 1:00:0 into the video after that it no longer worked like in the video.

/* Master Styles */
body {
    margin: 0px;

}

.container {
    display: grid;
    grid-template-columns: 1fr;
}

/* Nav Styles*/
.nav-wrapper{
    display:flex;
    justify-content: space-between;
    padding: 40px;
}

.left-side{
    display:flex;

}

.nav-wrapper > .left-side > div {
    margin-right: 20px;
    font-size: 0.9em;
    text-transform:uppercase;
}

.nav-link-wrapper {
    height: 22px;
    border-bottom: 1px solid transparent;
    transition: border-bottom 0.5s;
}

.nav-link-wrapper a {
    color:blue;
    text-decoration: none;
    transition: color 0.5s;
}

.nav-link-wrapper:hover{
    border-bottom: 1px solid black;
}

.nav-link-wrapper a:hover{
    color: black;
}

/* Portfolio Styles */
.portfolio-items-wrapper {
    display: grid;
    grid-template-columns: 1fr 1fr 1fr;
}

.portfolio-item-wrapper {
    position: relative;
}

.portfolio-img-background {
    height: 350px;
    width: 100%;
    background-size: cover;
    background-position: center;

}

.img-text-wrapper {
    position: absolute;
    top: 0;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    height: 100%;
    text-align: center;
    padding-left: 100px;
    padding-right: 100px;
}

.logo-wrapper img {
    width: 50%;
    margin-bottom: 20px;
}

.subtitle {
    font-weight: 600;
    color: darkblue;
}
<!DOCTYPE html>
<html>
<head>
    <title>Mathews Joy</title>
    <meta charset="utf-8">
    <link rel="stylesheet" href="styles.css">
</head>

<body>
    <div class="container">
        <div class="nav-wrapper">
            <div class="left-side">
                <div class="nav-link-wrapper">
                    <a href="https://www.linkedin.com/in/mathews-joy/">Personal LinkedIn Page</a>
                </div>

                <div class="nav-link-wrapper">
                    <a href="https://www.instagram.com/?hl=en">Personal Instagram Page</a>
                </div>
            </div>

            <div class="right-side">
                <div class="brand">
                    MATHEWS JOY
                </div>
            </div>
        </div>

        <div class="content-wrapper">
            <div class="portfolio-items-wrapper">

                <div class="portfolio-item-wrapper">
                    <div class="portfolio-img-backround" style="background-image:url(images/portfolio1.jpg)"></div>

                    <div class="img-text-wrapper">
                        <div class="logo-wrapper">
                            <img src="images/network.jpg">
                        </div>

                        <div class="subtitle">
                            Technology Intership at the Bright Network (December 2020)
                        </div>
                    </div>
                </div>

                <div class="portfolio-item-wrapper">
                    <div class="portfolio-img-backround" style="background-image:url(images/portfolio3.jpg)"></div>

                    <div class="img-text-wrapper">
                        <div class="logo-wrapper">
                            <img src="images/network.jpg">
                        </div>

                        <div class="subtitle">
                            Certications completed during time at university (2020 - 2023)
                        </div>
                    </div>
                </div>

                <div class="portfolio-item-wrapper">
                    <div class="portfolio-img-backround" style="background-image:url(images/portfolio2.jpg)"></div>

                    <div class="img-text-wrapper">
                        <div class="logo-wrapper">
                            <img src="images/network.jpg">
                        </div>

                        <div class="subtitle">
                            Volunteering and Work Experiences
                        </div>
                    </div>
                </div>

                
            </div>
        </div>


    </div>
</body>
</html>
question from:https://stackoverflow.com/questions/65849184/why-is-image-not-appearing-in-html

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

It's because there are no images at the URL's you are using. What's more, you need to apply a height to the elements that have the background images. I only did it for one of them below.

/* Master Styles */
body {
    margin: 0px;

}

.container {
    display: grid;
    grid-template-columns: 1fr;
}

/* Nav Styles*/
.nav-wrapper{
    display:flex;
    justify-content: space-between;
    padding: 40px;
}

.left-side{
    display:flex;

}

.nav-wrapper > .left-side > div {
    margin-right: 20px;
    font-size: 0.9em;
    text-transform:uppercase;
}

.nav-link-wrapper {
    height: 22px;
    border-bottom: 1px solid transparent;
    transition: border-bottom 0.5s;
}

.nav-link-wrapper a {
    color:blue;
    text-decoration: none;
    transition: color 0.5s;
}

.nav-link-wrapper:hover{
    border-bottom: 1px solid black;
}

.nav-link-wrapper a:hover{
    color: black;
}

/* Portfolio Styles */
.portfolio-items-wrapper {
    display: grid;
    grid-template-columns: 1fr 1fr 1fr;
}

.portfolio-item-wrapper {
    position: relative;
}

.portfolio-img-background {
    height: 350px;
    width: 100%;
    background-size: cover;
    background-position: center;

}

.img-text-wrapper {
    position: absolute;
    top: 0;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    height: 100%;
    text-align: center;
    padding-left: 100px;
    padding-right: 100px;
}

.logo-wrapper img {
    width: 50%;
    margin-bottom: 20px;
}

.subtitle {
    font-weight: 600;
    color: darkblue;
}
<!DOCTYPE html>
<html>
<head>
    <title>Mathews Joy</title>
    <meta charset="utf-8">
    <link rel="stylesheet" href="styles.css">
</head>

<body>
    <div class="container">
        <div class="nav-wrapper">
            <div class="left-side">
                <div class="nav-link-wrapper">
                    <a href="https://www.linkedin.com/in/mathews-joy/">Personal LinkedIn Page</a>
                </div>

                <div class="nav-link-wrapper">
                    <a href="https://www.instagram.com/?hl=en">Personal Instagram Page</a>
                </div>
            </div>

            <div class="right-side">
                <div class="brand">
                    MATHEWS JOY
                </div>
            </div>
        </div>

        <div class="content-wrapper">
            <div class="portfolio-items-wrapper">

                <div class="portfolio-item-wrapper">
                    <div class="portfolio-img-backround" style="background-image:url(images/portfolio1.jpg)"></div>

                    <div class="img-text-wrapper">
                        <div class="logo-wrapper">
                            <img src="https://via.placeholder.com/150

C/O https://placeholder.com/">
                        </div>

                        <div class="subtitle">
                            Technology Intership at the Bright Network (December 2020)
                        </div>
                    </div>
                </div>

                <div class="portfolio-item-wrapper">
                    <div class="portfolio-img-backround" style="background-image:url(https://via.placeholder.com/150); height: 200px"></div>

                    <div class="img-text-wrapper">
                        <div class="logo-wrapper">
                            <img src="https://via.placeholder.com/150

C/O https://placeholder.com/">
                        </div>

                        <div class="subtitle">
                            Certications completed during time at university (2020 - 2023)
                        </div>
                    </div>
                </div>

                <div class="portfolio-item-wrapper">
                    <div class="portfolio-img-backround" style="background-image:url(images/portfolio2.jpg)"></div>

                    <div class="img-text-wrapper">
                        <div class="logo-wrapper">
                            <img src="https://via.placeholder.com/150

C/O https://placeholder.com/">
                        </div>

                        <div class="subtitle">
                            Volunteering and Work Experiences
                        </div>
                    </div>
                </div>

                
            </div>
        </div>


    </div>
</body>
</html>

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...