2

I'm trying to create a simple website that has a Header containing the logo and other information, then a ribbon as separator and then a two-column section. Left column will have a selector. Right column will have information depending on the option chosen on the selector.

I was able to do this so far but now I wanna take it to the next level. I would like my site to always fit to the window so no vertical scrollbar needed. I'm comfortable with the sizes of my header and ribbon so I want the two-column section to take the remaining space in the window. The scrollbar, if needed, would be on the information div. Just in case, I want the left-half (selector) to take as much space as it needs. Right-half (information) should adjust to the space it has left.

I have this code so far:

CSS

.container {
    display: table;
    width: 100%;
}

.left-half {
    display: table-cell;
    background-color:#7ec0ee;
}
.right-half {
    display: table-cell;
    overflow: auto;
}

HTML

<div id="header" style="background-color:#7ec0ee; padding-top:20px; padding-left:5px; padding-bottom:20px" align="center">
    <div id="header-logo" align="left">
        <img src=".." alt="MDN" width="160" height="113">
    </div>
</div>
<div id="black-banner" style="background-color:black; padding:2px">&nbsp;</div>
<div id="container" class="container">
    <div class="left-half">
        <select>..</select>
    </div>
    <div id="content" class="right-half"></div>
</div>
Mickael Lherminez
  • 679
  • 1
  • 10
  • 29
Voldy10
  • 21
  • 2
  • 4
    Does this answer your question? [Make a div fill the height of the remaining screen space](https://stackoverflow.com/questions/90178/make-a-div-fill-the-height-of-the-remaining-screen-space) – iPhoenix Dec 18 '19 at 13:18

3 Answers3

1

Here I have use some bootstrap classes. I think this will help you out.

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
    <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css" integrity="sha384-Gn5384xqQ1aoWXA+058RXPxPg6fy4IWvTNh0E263XmFcJlSAwiGgFAW/dAiS6JXm" crossorigin="anonymous">
</head>
<body>
        <nav class="navbar navbar-dark bg-dark navbar-expand-lg">
                <a class="navbar-brand" href="#">Navbar w/ text</a>
                <button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarText" aria-controls="navbarText" aria-expanded="false" aria-label="Toggle navigation">
                  <span class="navbar-toggler-icon"></span>
                </button>
                <div class="collapse navbar-collapse" id="navbarText">
                  <ul class="navbar-nav mr-auto">
                    <li class="nav-item active">
                      <a class="nav-link" href="#">Home <span class="sr-only">(current)</span></a>
                    </li>
                    <li class="nav-item">
                      <a class="nav-link" href="#">Features</a>
                    </li>
                    <li class="nav-item">
                      <a class="nav-link" href="#">Pricing</a>
                    </li>
                  </ul>
                  <span class="navbar-text">
                    Navbar text with an inline element
                  </span>
                </div>
              </nav>
              <div class="container-fluid">
                    <div class="row">
                      <div class="col-sm" style="background-color: lavender">
                        One of three columns
                      </div>
                      <div class="col-sm" style="background-color: #EAE7EE">
                        One of three columns
                      </div>
                      <div class="col-sm" style="background-color: #E6E2EB">
                        One of three columns
                      </div>
                    </div>
                  </div>
</body> 
</html>
Gimnath
  • 824
  • 9
  • 11
1

I suggest using flex. It's fantastic for responsive designs. You can set the width in the flex property on your left or right halwes.

.container {
  display: flex;
  width: 100%;
  height: calc(100vh - 98px); //98px is the height of your header
}

.left-half {
  flex: 1;
  background: red;
}

.right-half {
  flex: 1;
  padding: 1em;
  overflow: auto;
  background: blue;
}
<div id="header" style="background-color:#7ec0ee; padding-top:20px; padding-left:5px; padding-bottom:20px" align="center">
  <div id="header-logo" align="left">
    <img src=".." alt="MDN" width="160" height="113">
  </div>
</div>
<div id="black-banner" style="background-color:black; padding:2px">&nbsp;</div>
<div id="container" class="container">
  <div class="left-half">
    <select>..</select>
  </div>
  <div id="content" class="right-half"></div>
</div>
Marius
  • 1,420
  • 1
  • 11
  • 19
0

This might work for you. you can make use of the calc function in CSS.

.container {
    display: flex;
    width: 100%;
    height: calc(100vh - 100px); //Replace this 100px with whatever value elements other than container are occupying
}

.left-half {
  width:50%;
  background-color:#7ec0ee;
}
.right-half {
    background: red;
    width: 50%;
}
Bikram Jethi
  • 312
  • 2
  • 11