Welcome!

By registering with us, you'll be able to discuss, share and private message with other members of our community.

SignUp Now!
  • Guest, before posting your code please take these rules into consideration:
    • It is required to use our BBCode feature to display your code. While within the editor click < / > or >_ and place your code within the BB Code prompt. This helps others with finding a solution by making it easier to read and easier to copy.
    • You can also use markdown to share your code. When using markdown your code will be automatically converted to BBCode. For help with markdown check out the markdown guide.
    • Don't share a wall of code. All we want is the problem area, the code related to your issue.


    To learn more about how to use our BBCode feature, please click here.

    Thank you, Code Forum.

Help with making fixed element respect the with of the max body width

I have a problem where my navbar which is fixed to the right side of the screen, does not respect the 1440px max width of the body.

So my question is: How can i make sure the navbar never extends past the 1440px max width of the body?

HTML:
<body>
    <nav>
        <div class="nav-upper">
            <img class="nav-logo" src="img/logo.svg" alt="Staugaard Studio logo">
            <div class="nav-collapse-btn">
                <h2>Navigation</h2>
                <img class="nav-arrow" src="img/arrow-down.svg" alt="nav indicator">
            </div>
            <div class="nav-collapse">
                <a class="nav-collapse-link" href="">Om mig</a>
                <a class="nav-collapse-link" href="">Projekter</a>
                <a class="nav-collapse-link" href="">Kontakt</a>
            </div>
        </div>
        <div class="nav-lower">
            <h2>©2022</h2>
            <a class="nav-btn" href="">KONTAKT</a>
        </div>
    </nav>
</body>

CSS:
nav {
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    height: 100vh;
    position: fixed;
    top: 0;
    right: 0;
    padding: 40px 20px 40px 20px;
    border-left: #242325 solid 2px;
    box-sizing: border-box;
}

body {
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    max-width: 1440px;
    padding: 40px;
    margin: 0 auto;
    background-color: #FFF8F2;
}
 
Back
Top Bottom