-1

I need to make the child height relative to the viewport. Using HTML:

<div class="parent">My divider
  <div class="child">
      Inside the div
  </div>
</div>

and CSS:

.t1 {
    background:#f00;
    color:#fff;
}

.t2 {
  background:#212121;
  height:100vh;
}

http://jsfiddle.net/hr8sL/7646/

As you can see from the example, There's always this small gap, because it takes into account the overall height of the parent. However, I only need the child to fill "the rest" of the viewport from parent.

How should I proceed? I've tried many other things, but without sufficient result

Actolia
  • 125
  • 2
  • 7
  • I'm not quite sure what you're asking. Are you asking how to remove the small gap **between** `t1` and `t2`? Can you not just give `t2` a negative `margin-top`? Or are you asking how to make `t2` take up `100%` of the **remaining** height? That would be done with `calc()`. – Obsidian Age Mar 01 '18 at 23:04
  • I don't see `position:fixed` anywhere in your code. – Kosh Mar 01 '18 at 23:11

1 Answers1

0

I would do it like this.

Using the css calc() function we can calculate the remaining height.

body {
  margin: 0;
  /* This is used to reset any browser-default margins */
}

.t1 {
  background: #f00;
  color: #fff;
  height: 20px;
}

.t2 {
  background: #212121;
  height: calc(100vh - 20px);
}
<div class="t1">
  My divider
</div>
<div class="t2">
  Inside the div
</div>
E. Sundin
  • 4,103
  • 21
  • 30