Welcome to Code Forum!

Join a community that supports you and your coding journey from day one. We strive to be a friendly, supportive community that empowers everyone to be better developers. 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.

    GIF shows where to locate </> in the thread and or post editor toolbar.
    To learn more about how to use our BBCode feature, review our "How to post your code into threads" here.

    Thank you, Code Forum.

Help needed. How to make a fixed element not exted past the body max width

I have a navbar on my site which is fixed to the right side of the screen. But the problem is that i want it to be fixed so that it does not extend past the max body width of 1440px. How could i achieve this?

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 25px 40px 25px;
    border-left: #242325 solid 2px;
    box-sizing: border-box;
}

body {
    max-width: 1440px;
    padding: 40px;
    margin: 0 auto;
    background-color: #FFF8F2;
}
 
My screen is over 2000px and I see nothing happening that looks bad when I stretch your page to those limits. The side column remains the same size and firmly up against the right side of the page.
What do you see happening?
 

Buy us a coffee!

Buy me a coffee.
Back
Top Bottom