Fixed position not working properly


<!-- header section  -->
    <header id="header">
        <div class="logo">
            <img src="" alt="trombone Logo">

        <nav id="nav-bar">
                <li><a href="#features-section">Features</a></li>
                <li><a href="#video-section">How it works</a></li>
                <li><a href="#pricing-section">Pricing</a></li>

<!-- header section ends here -->

<!-- email section starts here -->

<section id="email-section">
    <h2 id="email-heading">
        Handcrafted,home-made masterpieces
    <form id="form">
        <input type="email" id="email-input" placeholder="Enter your email address">
        <input type="submit" id="submit-input" value="GET STARTED">

<!-- email section ends here -->


@import ",700";

    background-color: rgb(238, 238, 238);
    font-family: lato;
/* header styling starts here */

    list-style: none;
    text-decoration: none;
    color: black;

    display: flex;
    justify-content: space-between;
   /* position: fixed;*/


    display: flex;
    justify-content:  center;
    align-items: center;
    width: 100%;
    margin-left: 20%;

    max-width: 300px;

#nav-bar > ul{
    display: flex;
    justify-content:  space-around;

@media (max-width: 700px)
        flex-direction: column;
    #nav-bar > ul{
        flex-direction: column;
        justify-content: center;
        align-items: center;
        margin-left: 0px;

        padding-top: 4px;

/* header styling ends here */

/* email styling starts here */

    display: block;
    margin-bottom: 10px;
    padding: 7px 10px 7px 10px;
    font-size: 14px;
    min-width: 300px;
    display: block;
    background-color: rgb(239, 207, 0);
    border: none;
    padding: 5px 10px 5px 10px;
    font-size: 15px;

    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;

    text-align: center;

/* email styling ends here */

When I adding position: fixed to #header element to make the header fixed at the top, everything gets messy . I don’t know why this is happening and how to fix this . Please help me to understand this …what’s going on there.

Most likely you have other elements overwritting this.
I ussually solute it the next way.
Remove everything expect what you need. To test if it works correctly without anything intervening it.
Does it do what you wanted now?
If yes then you know something else is overwritting it.
No then something in your code is wrong. Check your spelling and compare to correct code.

remove it from header // other elements in header
put to
width: 30%; // adjust
margin-left: 70%; //adjust
position: fixed; }