5

Hi I am currently working on a small web interface. My problem is a vertical scrollbar which appears even though I have set the

body{
        height:100vh;
        margin:0;
        padding:0;
    }

For my understanding this should set the height of the body to the full height of the viewport while removing every margin / padding. This means that there is no space around the body so there shouldn't be any scrolling.

Here is a screenshot from the current view. The current view As you can see there is a vertical scrollbar aswell as the footer not being shown correctly.

My Current code can be found here:

:root {
  --white: #FFFFFF;
  --grey_237: #EDEDED;
  --grey_220: #DCDCDC;
  --grey_178: #B2B2B2;
  --grey_107: #6B6B6B;
  --functional_red: #D90000;
  --fucntional_yellow: #FECB00;
  --functional_green: #46A800;
  --functional_blue: #009DE0;
  --company: #544b83
}

.card-3 {
  grid-column-end: span 3
}

.card-4 {
  grid-column-end: span 4
}

.card-5 {
  grid-column-end: span 5
}

.card-10 {
  grid-column-end: span 10
}

.justify_right {
  justify-items: end;
  text-align: end
}

.no_margin {
  margin: 0
}

.no_padding {
  padding: 0
}

.start-1 {
  grid-column-start: 1
}

.start-2 {
  grid-column-start: 2
}

.start-3 {
  grid-column-start: 3
}

.start-4 {
  grid-column-start: 4
}

.start-5 {
  grid-column-start: 5
}

.deep-2 {
  grid-row-end: span 2
}

.uppercase {
  text-transform: uppercase
}

.card {
  background-color: #fff
}

body {
  background-color: var(--grey_237);
  display: grid;
  grid-template-rows: auto 1fr auto;
  grid-gap: 25px;
  height: 100vh;
  margin: 0;
  padding: 0;
}

.container {
  max-width: 90%
}

#content {
  height: 100%;
  display: grid;
  grid-template-columns: repeat(12, 1fr);
  grid-template-rows: repeat(4, 1fr);
  grid-gap: 25px
}

.color_bg {
  background-color: var(--company);
  color: var(--white)
}

#brand_header {
  display: grid;
  height: 70px;
  text-align: center;
  align-content: center
}

#slogan {
  display: grid;
  align-content: center;
  font-weight: 900
}

#branding_title {
  font-weight: 700;
  color: var(--company)
}

#content_title {
  color: var(--company);
  font-size: 3em;
  font-weight: 900;
}

.card_title {
  font-weight: 600!important;
  font-size: 2em
}

.card-right {
  display: grid;
  grid-template-columns: 1fr 1fr
}

.card-right .card-body {
  display: grid;
  grid-gap: 5px
}

.card_change {
  display: grid;
  grid-template-columns: auto 1fr;
  grid-gap: 5px;
  align-items: center
}

.card_value {
  display: grid;
  align-self: end
}

.card_change {
  display: grid;
  align-self: start
}

.card_graph {
  background-image: url(https://via.placeholder.com/150x150?text=graph);
  background-size: cover;
  background-position: center
}

#trends {
  background-image: url(https://via.placeholder.com/550x350?text=graph);
  background-size: cover;
  background-position: center
}

#footer {
  display: grid;
  height: 40px;
  background-color: white;
  display: grid;
  align-items: center
}
<!doctype html>
<html lang="en">

<head>
  <!-- Required meta tags -->
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">

  <!-- Bootstrap CSS -->
  <link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.2.1/css/bootstrap.min.css" integrity="sha384-GJzZqFGwb1QTTN6wy59ffF1BuGJpLSa9DkKMp0DgiMDm4iYMj70gZWKYbI706tWS" crossorigin="anonymous">

  <!--  custom css -->
  <link rel="stylesheet" href="style.css">


  <title>Site</title>
</head>

<body>
  <div id="header">
    <div id="brand_header" class="color_bg">
      <div class="container">
        <div id="header_text" class="row justify-content-between">
          <div id="slogan" class="justify_right">
            <p class="no_margin uppercase">Our slogan</p>
          </div>
        </div>
      </div>
    </div>
    <div id="navbar">
      <nav class="navbar navbar-light bg-light">
        <div class="container no_padding">
          <span class="navbar-brand no_margin uppercase" id="branding_title">
                        Our Team
                    </span>
        </div>
      </nav>
    </div>
  </div>


  <div id="content" class="container no_padding">
    <div class="card-3 start-1">
      <h2 id="content_title">title</h2>
    </div>

    <div id="card_1" class="card card-3 start-1 card-right">
      <div class="card-body">
        <h5 class="card_title text-muted">Card 3</h5>
        <h2 class="card_value no_margin">Data</h2>
        <div class="card_change">
          <span id="card_1_change_value" class="change_value">change</span>
        </div>
      </div>
      <div id="card_1_graph" class="card_graph thumbnail ">
        <div class="chart-container" style="position: relative; width:99%; height:99%;">
          <canvas id=""></canvas>
        </div>
      </div>
    </div>

    <div id="trends" class="card card-10 deep-2 ">
      <div class="chart-container" style="position: relative; width:99%; height:99%;">
        <canvas id=""></canvas>
      </div>
    </div>


  </div>




  <div id="footer">
    <div class="container">
      footer
    </div>
  </div>

  <!-- Optional JavaScript -->
  <!-- jQuery first, then Popper.js, then Bootstrap JS -->
  <script src="https://code.jquery.com/jquery-3.3.1.slim.min.js" integrity="sha384-q8i/X+965DzO0rT7abK41JStQIAqVgRVzpbzo5smXKp4YfRvH+8abtTE1Pi6jizo" crossorigin="anonymous"></script>
  <script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.6/umd/popper.min.js" integrity="sha384-wHAiFfRlMFy6i5SRaxvfOCifBUQy1xHdJ/yoi7FRNXMRBu5WHdZYu1hA6ZOblgut" crossorigin="anonymous"></script>
  <script src="https://stackpath.bootstrapcdn.com/bootstrap/4.2.1/js/bootstrap.min.js" integrity="sha384-B0UglyR+jN6CkvvICOB2joaf5I4l3gm9GU6Hc1og6Ls7i6U/mkkaduKaBhlAXv9k" crossorigin="anonymous"></script>
</body>

</html>

A link to codepen can be found here:
Codepen Link


There will be some charts inside the cards. That is the reason why there is the following snippet:
<div class="chart-container" style="position: relative; width:99%; height:99%;">
    <canvas id=""></canvas>
</div>

It was created according to the documentation of chart.js


My Idea of the problems cause

My current idea is that the content of the body is to big in order to be rendered correctly. While this sounds like a reasonable cause I don't know why this occured since I was using relative units.

I'd be happy for your assistance and I'd like to thank everybody in advance.


Added later:

I tried to use

overflow:hidden;

The problem here is, even though it solves the scrollbar problem the webpage is still not showing the while view (only half the footer)


I was looking through the dev tools when I've been seeing this: img_through_dev_tools It seems like the body is scaling correctly (100vh) but the footer seems to be partially rendered outside the body. Don't know why this is happening but it seems interesting.


There was the idea that my grid-gap is causing the issue since it forces a gap. I was testing this here and it's not the problem since the fr unit is adjusting accordingly.

body {
  margin: 0;
  padding: 0;
  height: 100vh;
}

.content {
  height: 100%;
  display: grid;
  grid-template-rows: 1fr 1fr;
  grid-gap: 25px;
}

#div1 {
  background-color: aquamarine;
}

#div2 {
  background-color: blanchedalmond;
}
<!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">
  <link rel="stylesheet" href="style.css">
  <title>Document</title>
</head>

<body>
  <div class="content">
    <div id="div1">
      This is div 1
    </div>
    <div id="div2">
      This is div 2
    </div>
  </div>
</body>

</html>

I then tried the same but with margin instead of grid-gap. The result is still the same as fr is not only adjusting to grid-gap but also all the other paddings / margins.

body {
  margin: 0;
  padding: 0;
  height: 100vh;
}

.content {
  height: 100%;
  display: grid;
  grid-template-rows: 1fr 1fr;
}

#div1 {
  background-color: aquamarine;
}

#div2 {
  margin-top: 25px;
  background-color: blanchedalmond;
}
<!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">
  <link rel="stylesheet" href="style.css">
  <title>Document</title>
</head>

<body>
  <div class="content">
    <div id="div1">
      This is div 1
    </div>
    <div id="div2">
      This is div 2
    </div>
  </div>
</body>

</html>
Michael Benjamin
  • 346,931
  • 104
  • 581
  • 701
Ironlors
  • 173
  • 3
  • 19
  • 1
    `This means that there is no space around the body so there shouldn't be any scrolling.` --> the scroll is not on the body as you may think but in an upper level – Temani Afif Jan 31 '19 at 11:33
  • But if everything fits onto the page (which should happen) there wouldn't be any scrolling. So what I don't understand is why everything won't fit onto the page. – Ironlors Jan 31 '19 at 11:36
  • yes a bit complex situtation, I am trying to figure out the why ;) – Temani Afif Jan 31 '19 at 11:41
  • The content doesn't fit in the viewport because the viewport isn't large enough to hold all the content, it's that simple. If you zoom out, the scrollbar goes away once everything fits. – Mr Lister Jan 31 '19 at 11:43
  • @MrLister but why is this the case since I'm using relative units. Shouldn't they scale accordingly for my content to properly fit? – Ironlors Jan 31 '19 at 11:44
  • @MrLister all his properties are filled with `fr` thus logically everything should shrink ... even if you remove `height:100vh` and `height:100%` we have the issue – Temani Afif Jan 31 '19 at 11:46
  • 1
    it's has something to do with the 1fr or the rows but not able to get it right ... – Temani Afif Jan 31 '19 at 11:52
  • It might be caused by your ‘grid-gap’ styling that’s forcing a 25px spacing between elements in the grid. – Randy Jan 31 '19 at 12:00
  • @Randy I was testing this and put my findings into the question. TLDR: it's not the problem – Ironlors Jan 31 '19 at 12:39
  • 3
    Not a margin or padding issue. Grid items (like flex items) cannot, by default, be smaller than their content. The problem you're having is that the content inside your `#content` element is forcing the grid area to exceed the boundaries of the container. You have at least two possible solutions. [revised codepen demo](https://codepen.io/anon/pen/yZgqpV) – Michael Benjamin Jan 31 '19 at 13:17
  • @Michael_B **Thanks** a lot. This seems to fix the problem. Would you mind putting this as an answer so I can acknowledge it as a solution. – Ironlors Jan 31 '19 at 13:26
  • 1
    @Ironlors, I just noticed that *both* solutions are necessary for the layout to work in FF and Edge. Only one solution (either one) is enough for Chrome. – Michael Benjamin Jan 31 '19 at 13:27
  • @Michael_B but you can clearly see that one row defined by `1fr` (the first one) has a lot of space, why it doesn't shrink to the content, same the last row – Temani Afif Jan 31 '19 at 15:49
  • Where? Not sure which grid you're referring to, and I don't see the problem you're describing. @TemaniAfif – Michael Benjamin Jan 31 '19 at 15:54
  • @Michael_B the grid item that contain `title` (here a screenshot : https://imgur.com/a/Rw95KLj) Using Chrome by th way – Temani Afif Jan 31 '19 at 15:59
  • I'm not seeing that at all, on Chrome or any other browser. Are you sure you're using my revised code? https://codepen.io/anon/pen/pGRGQM?editors=1100 – Michael Benjamin Jan 31 '19 at 16:01
  • @Michael_B no, I meant in the OP code (the snippet in the question) – Temani Afif Jan 31 '19 at 22:15
  • @TemaniAfif, because with `1fr` on all rows, layout resolves to equal height rows. https://stackoverflow.com/q/44488357/3597276 – Michael Benjamin Feb 01 '19 at 00:02
  • 1
    @Michael_B yes I was missing that part. Well I guess, we also need this link as duplicate to fully understand what is happening. – Temani Afif Feb 01 '19 at 00:26

0 Answers0