How to extend a DIV to the end of the screen?

Asked

Viewed 3,722 times

1

Well I created a main div to hold all the elements of the page. Inside it I have 3 others divs: 1 menu bar, 1 sidebar, 1 content area.

HTML:

<div class="principal">
  <div class="barra_menu">
    Barra de menu
  </div>
  <div class="menu_lateral">
    <!--Como se estende esse div até o fim da página/elemento pai-->
    Menu lateral:<br>.<br>.<br>.
  </div>
  <div class="area_conteudo">
    Area de conteudo:<br>.<br>.<br>.<br>.<br>.<br>.<br>.<br>.<br>.
  </div>
</div>

CSS:

.principal{background-color:red;height:100%;}
.barra_menu{background-color:gray;widht:100%;}
.menu_lateral{background-color:blue;width:30%;float:left;}
.area_conteudo{background-color:green;width:70%;float:left;}

I want the side menu to extend from where it is to the bottom of the page, but I don’t know the solution.

I would like to get a solution based only on HTML/CSS preferably without using absolute positioning.

Following is a visual example of what I want to do: https://jsfiddle.net/m17wuaLc/2/

3 answers

1

I recommend using the technique of Sticky Footer, if there is a need for compatibility with older browsers.

Your HTML structure would look like this:

* {
  margin: 0;
}
html, body {
  height: 100%;
}
.page-wrap {
  min-height: 100%;
  /* equal to footer height */
  margin-bottom: -142px; 
}
.page-wrap:after {
  content: "";
  display: block;
}
.site-footer, .page-wrap:after {
  height: 142px; 
}
.site-footer {
  background: orange;
}
.side-left{
  float:left;
  width: 30%;
}
.content{
  float:left;
  width: 70%;
}
<div class="page-wrap">
  <div class="side-left">
    Menu
  </div>
  
  <div class="content">
    Content!
  </div>
      
</div>

<footer class="site-footer">
  I'm the Sticky Footer.
</footer>

  • You can add an example of use to the answer?

  • Yes, of course. But the link has the full details.

  • It is because response with links are just not within the type of response that the site accepts as positive. To serve as a reference in the future, if this link no longer exists, it would be interesting to have an example of use in the answer too.

  • All right, example included.

  • I found this technique very interesting, but what I am doing here does not have a fixed footer, is a layout that resembles an application

0

You can use the property:

1vh (viewport height) = 1% of viewport height

will stay like this

min-height:100vh;
  • the side menu is not located at the top of the page, there is a vertical bar before it. when applying the proposed property the menu is extended beyond the screen limit. I look for a solution that extends the menu from the position where it is until the end of the screen

0

First you must give to the body one

height: 100%

And to your right-side menu, the same. It would look like this:

body{
   height: 100%
}
.menu_lateral{
   height: 100%;
}

The body has a standard height: auto

Because of this the body will extend to the size of the largest element. Giving a height: 100% this will be undone and it will have the screen size.

  • the detail that the side menu is not located at the top of the page, there is a menu bar before it. So if applying a 100% height in the side menu will be considered the body size relative to the position it is located, which extends the side menu beyond the screen/parent element limit

  • I wanted him to take the position he’s in until the end of the screen

  • Look at this jsfiddle, if that’s what you wanted, I’ll explain in detail what I did. https://jsfiddle.net/m17wuaLc/6/

  • Samir Raga, ends up entering the problem of all the answers so far, as there is a menu bar before the side menu is assigned to the element the height:100% considering the position that the element is, stretching the menu beyond the screen limit... compare your example with this: https://jsfiddle.net/m17wuaLc/7/

  • I do not understand what you mean, if you are referring to the fact that the sidebar exceeds the menu, this did not happen in my example. Even when I assign a height to the top menu. Look at https://jsfiddle.net/m17wuaLc/8/ .

Browser other questions tagged

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