2 years ago

Bootstrap 4 - Fixed navbar full width collumn

Posted 2 years ago by Rainieren

Hello, I'm making a dashboard and I want to have a fixed navbar in bootstrap that is the full width of my column which is col-md-10 But when I add position: fixed; to the navbar the navbar stretches 100% across the whole page instead of staying in the column. How can I solve this? Here is an image of what I am trying to achieve: https://imgur.com/a/xp4mC The navbar needs to be the full width of the blue column. In the picture it is but it does not have position: fixed;, If I add that, however. It will look like this.: https://imgur.com/a/GYdYQ

Here is the code:

<div class="container" style="max-width: 100%; margin: 0;">
    <div class="row">
        <div class="col-md-2" style="background-color: red; height: 100px;">

        <div class="col-md-10" style="background-color: blue; height: 100px; padding: 0;">

            <nav class="navbar navbar-expand-lg navbar-light z-depth-3 border-none" style="background-color: #ffffff; padding-top: 12px; padding-bottom: 12px;">
                <div class="container-fluid" style="padding-left: 0;">
                    <button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarSupportedContent" aria-controls="navbarSupportedContent" aria-expanded="false" aria-label="Toggle navigation">
                        <span class="navbar-toggler-icon"></span>
                    <a class="navbar-brand" href="#">Navbar</a>
                    <div class="collapse navbar-collapse" id="navbarSupportedContent">
                        <ul class="navbar-nav mr-auto">
                            <li class="nav-item">

                        <ul class="navbar-nav">
                            <li class="nav-item">
                                <a class="nav-link dropdown-toggle" href="#" id="navbarDropdown" role="button" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
                                    <span class="hidden-xs-only">John Doe</span>
                                <div class="dropdown-menu pull-right" aria-labelledby="navbarDropdown">
                                    <a class="dropdown-item" href="#">Action</a>
                                    <a class="dropdown-item" href="#">Another action</a>
                                    <a class="dropdown-item" href="#">Something else here</a>


How can I solve this?

Thanks in advance

Please sign in or create an account to participate in this conversation.