Side div with 100% height with Bootstrap 4

Asked

Viewed 3,217 times

1

Good afternoon, you guys. I am breaking my head with the side menu of my site, I want it to be 100% height (using height:100% did not work), the problem is this, searching the internet I saw the tip to use the margin-bottom: -9999px; padding-bottom: 9999px; worked in parts, because div occupies more than the screen getting the scroll on the side, another problem is that your site is responsive, so on smaller screens the rest of the content ends up getting behind this menu, what I want to do exactly and the following:

I want my side menu to complete the entire screen height, but when I lower the screen it does not overlap the rest of the content, I don’t know if I was clear enough:

Follows my CSS:

html, body {
height: 100%;
overflow: auto;
}

body {
background: linear-gradient(50deg,#6c757d,#dee2e6);
background-attachment: fixed;
font-family: Helvetica,Arial,sans-serif;
overflow-x: hidden;
}

.nav-side-menu {
font-family: Helvetica,Arial,sans-serif;
color: #dee2e6;
overflow: hidden;
font-size: 14px;
margin-bottom: -9999px;
padding-bottom: 9999px;
border-top-right-radius: 5px;
}

HTML

<div class="container-fluid">
<div class="row">

    <!-- Inicio Sidebar -->
    <div class="col-sm-2" id="sidebar-collapse"> 
        <div class="nav-side-menu bg-dark" >

            <div class="sidebar-profile-pic"></div>
            <span class="nav-link sidebar-profile-name">Douglas Nickson</span>
            <div class="divider"></div>

            <ul class="nav" style="display:block;">
                <li><a href="index.html"><i class="fa-lg fa fa-dashboard" aria-hidden="true"></i> Dashboard</a></li>
                <li class="parent"><a data-toggle="collapse" href="#modulo-item-1">
                    <i class="fa-lg fa fa-book">&nbsp;</i> Modulo <span data-toggle="collapse" href="#sub-item-1" class="icon pull-right"><em class="fa fa-plus"></em></span></a>
                    <ul class="children collapse" id="modulo-item-1">
                        <li><a class="" href="cadastrar-modulo.html">
                            <span class="fa fa-arrow-right">&nbsp;</span> Cadastrar Modulo
                        </a></li>
                        <li><a class="" href="#">
                            <span class="fa fa-arrow-right">&nbsp;</span> Gerenciar Modulo
                        </a></li>
                    </ul>       
                </li>

            </ul>

        </div>
    </div><!-- Fim Sidebar -->

    <div class="col-sm-10">

        <section class="dashboard">


        </section>

    </div>
</div>
</div>
  • Post your HTML file. If you set height to 100% it should already work, unless their top parents have no defined height, which is common in bootstrap...

  • 1

    @Diegosantos html added, I put the height 100% in the side div, and the container div that and the parent div, and even then it didn’t work.

  • see in my reply, if it meets you...

1 answer

1

You see, I was able to play the 100% heigth, but I had to move some classes. It might help you, but I recommend revising the structure of your HTML. Maybe by putting the menu out of the container. Or by setting in the container and in the specific Row, the height: 100%.

Remembering that ALL parent elements must be at set height to work

.

html, body {
height: 100%;
overflow: auto;
}

body {
background: linear-gradient(50deg,#6c757d,#dee2e6);
background-attachment: fixed;
font-family: Helvetica,Arial,sans-serif;
overflow-x: hidden;
}

.nav-side-menu {
font-family: Helvetica,Arial,sans-serif;
color: #dee2e6;
overflow: hidden;
font-size: 14px;
height: 100%;
width: 40%;
border-top-right-radius: 5px;
background-color: red;
}

#sidebar-collapse, .row, .container-fluid{
 height: 100%; 
}
<div class="container-fluid">
<div class="row">

    <!-- Inicio Sidebar -->
    <div class="col-sm-2" id="sidebar-collapse"> 
        <div class="nav-side-menu bg-dark" >

            <div class="sidebar-profile-pic"></div>
            <span class="nav-link sidebar-profile-name">Douglas Nickson</span>
            <div class="divider"></div>

            <ul class="nav" style="display:block;">
                <li><a href="index.html"><i class="fa-lg fa fa-dashboard" aria-hidden="true"></i> Dashboard</a></li>
                <li class="parent"><a data-toggle="collapse" href="#modulo-item-1">
                    <i class="fa-lg fa fa-book">&nbsp;</i> Modulo <span data-toggle="collapse" href="#sub-item-1" class="icon pull-right"><em class="fa fa-plus"></em></span></a>
                    <ul class="children collapse" id="modulo-item-1">
                        <li><a class="" href="cadastrar-modulo.html">
                            <span class="fa fa-arrow-right">&nbsp;</span> Cadastrar Modulo
                        </a></li>
                        <li><a class="" href="#">
                            <span class="fa fa-arrow-right">&nbsp;</span> Gerenciar Modulo
                        </a></li>
                    </ul>       
                </li>

            </ul>

        </div>
    </div><!-- Fim Sidebar -->

    <div class="col-sm-10">

        <section class="dashboard">


        </section>

    </div>
</div>
</div>

  • 1

    It worked friend, thank you very much, I will test and try to improve my code, but at first your solution solved what I wanted. Thank you very much!

  • Imagine... But I really recommend you take the menu away. Whenever I did this way I had many problems rsrs.

  • however, aperriando again, I saw now that a problem is happening, the side menu does not follow the content, in my case the menu expands, when I open all some options are cut, has to fix it?

  • Um, this is a problem I’ve had many times. hahah Try taking the menu out of the structure. It will be only body child. Position it with display: Fixed. Position the page content. This way you can scroll the page or do anything that it will not move

  • Did the test, did not work, the lateral div does not follow the internal content.... :(

  • Do so, ask another question here is put the code. Easier. So it becomes abstract for me heheh

  • https://answall.com/questions/279635/div-n%C3%A3o-conte%C3%Bado-interno-bootstrap-4

Show 2 more comments

Browser other questions tagged

You are not signed in. Login or sign up in order to post.