Search code examples
javascripthtmlcssweb

Positioning A Header Below A Linear Gradient


Okay so I am learning HTML and CSS and I came across a little problem this afternoon.

I have tried so hard to fix this code for over 3 hours and it is still giving me the same output. So after the last div closing tag in the HTML document, I tried to make a header and a new h1 element but the problem is that, it appears in the purple like background in the gradient background which I don't want. I have tried several ways and means to fix the issue but I still end up with the same result.

`<!DOCTYPE html>
<html lang="en-US">
    <head>
        <meta charset="utf-8" >
        <title>HomePage</title>
        <meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=1">
        <link rel="stylesheet" href="style.css" >
    </head>
    <body>
        <div>
            <nav>
                <ul class="up-nav" id="dropdownClick">
                    <li><a href="#">Home</a></li>
                    <li><a href="#">Join Us</a></li>
                    <li><a href="#">Sign In</a></li>
                    <li class="up-nav-right"><a href="#">Contact Us</a></li>
                    <li class="dropdownIcon"><a href="javascript:void(0)" onclick="dropdownMenu()">&#9776;</a></li>
                </ul>
            </nav>
        </div>

        <div class="container" id="section-gradient">
            <div class="row">
                <div class="col-6">
                    <div>
                        <h1 class="big">Hi Sofie</h1>
                        <h1 class="big">Join Our Newsletter</h1>
                    </div>
                        <form>
                            <div>
                                <h2>First Name</h2>
                                <input class="inputfield" type="text" placeholder="First Name" name="First Name Here">
                                <h2>Email Address</h2>
                                <input class="inputfield" type="email" placeholder="Email Address" name="Email Address Here">
                            </div>
                        </form>
                </div>
            <div class="col-6">
                    <div class="rightSideCol">
                        <div class="videoEmbed">
                            <iframe width="560" height="315" src="https://www.youtube.com/embed/E6PTwrT5gFM" title="YouTube video player" frameborder="0" allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in- picture; web-share" allowfullscreen></iframe>
                        </div>
                    </div>

            </div>
        </div>
        <header>
            <h1>Lorem Ipsum</h1>
        </header>
        

        <script>
            function dropdownMenu() {
                var x = document.getElementById("dropdownClick");
                /*#####Change up-nav to up.nav.respond#####*/
                if (x.className === "up-nav") {
                    x.className += " respond";
                } 
                else {
                    x.className = "up-nav"
                }
            }
        </script>
    </body>
</html>
`


And this is the CSS for it 
`/*############ Defaults ##############*/
nav, header, footer {
    display: block;
}

body {
    margin: 0;
    line-height: 1;
}

.container {
    width: 100%;
    margin:auto;
    padding-top: 5%;
    padding-bottom: 5%;
}

#section-gradient {
    background: linear-gradient(180deg,#7C4CCF 0%, #3F2B96 100%);
}

h1.big {
    color: #fff;
    font-size: 56px;
    margin:0;
    margin-left: 20px;
    line-height: 75px;
}

input[type="text"] {
    width: 200px;
    min-width: 100px;
    font-size: 25px;
    padding: 5px;
    margin-left: 20px;
    border-radius: 7px;

}

input[type="email"] {
    width: 400px;
    font-size: 25px;
    min-width: 200px;
    padding: 5px;
    margin-left: 20px;
    border-radius: 7px;
}


form h2 {
    color: #fff;
    margin-left: 20px;
}

.row {
    width: 100%;
    display: flex;
    flex-wrap: wrap;
    align-items: center;
}

.row::after {
    display: table;
    clear: both;
    content: "";
}

.col-1 {width: 8.33%;}
.col-2 {width: 16.66%;}
.col-3 {width: 25%;}
.col-4 {width: 33.33%;}
.col-5 {width: 41.66%;}
.col-6 {width: 50%;}
.col-7 {width: 58.33%;}
.col-8 {width: 66.66%;}
.col-9 {width: 75%;}
.col-10 {width: 83.33%;}
.col-11 {width: 91.66%;}
.col-12 {width: 100%;}

/*############# Nav Bar Default ###############*/
nav {
    width: 100%;
    margin: 0;  
}

/*############# Nav Bar Links Arrangement ##############*/
nav ul {
    background-color: #eee;
    overflow: hidden;
    margin: 0;
    padding: 0;
    list-style: none;
}

/* Float this to the left*/
ul.up-nav li {
    float: left;
}

/* Float this to the right*/
ul.up-nav li.up-nav-right {
    float: right;
}

ul.up-nav li a {
    display: block;
    text-decoration: none;
    min-height: 16px;
    padding: 14px;
    text-transform: uppercase;
    text-align: center;
    color: #666;
}

/*############## Hover Effect On Links In Top Nav#################*/
ul.up-nav li a:hover {
    background-color: #7C4CCF;
    color: #fff;
}

/*############ Making The Trigram Dissapear In Desktop Mode ###############*/
ul.up-nav li.dropdownIcon {
    display: none;
}

/*########Making The Trigram Appear In Mobile Mode Using A Media Query#########*/
@media screen and (max-width:680px) {
    ul.up-nav li:not(:nth-child(1)) {
        display: none;
    }
    ul.up-nav li.dropdownIcon {
        display: block;
        float: right;
    }
    ul.up-nav.respond li.dropdownIcon {
        position: absolute;
        top: 0;
        right: 0;
    }
    ul.up-nav.respond {
        position: relative;
    }
    ul.up-nav.respond li {
        display: inline;
        float: none;
    }
    ul.up-nav.respond li a {
        display: block;
        text-align: left;
    }

    .col-6 {
        margin: 30px;
    }
    input[type="text"] {
        width: 350px;
    }

    input[type="text"] {
        width: 400px;
    }

    .videoEmbed iframe {
        position: relative;
        width: 100%;
        margin: 0;
        overflow: hidden;
    }
}`

Solution

  • You're missing a closing </div> tag before the opening <header> tag.

    As a side note, you should only ever have one <h1> tag per page. It is your most important heading. Read up more on heading tags here.

    <h1 class="big">Hi Sofie</h1>
    <h1 class="big">Join Our Newsletter</h1>
    

    Should become

    <h1 class="big">Hi Sofie<br> Join Our Newsletter</h1>