tarek hassan
tarek hassan

Reputation: 802

Why I can't get full length page even with height 100% and height 100vh?

I am building simple web app looks like Slack, I have a problem with making the page takes full width and height. The problem is that it actually ends taking half of it and other times taking longer but the left Navbar is not taking taking the same dimensions, the top 60% of left navigation appears with different background color than the bottom 40%.

I have included the snippet, I added several parameters 'height:100%' and 'height:100vh' and added them to *, html and body but always somehow turns to something not right.

* {
  font-size: 16px;
  margin: 0;
  padding: 0;
}
.app {
  display: flex;
  flex-direction: row;
}
.leftNav {
  border-right: 1px solid black;
  width: 17%;
  padding: 0px;
  margin: 0;
  background-color: lightslategray;
  color: white;
}
.leftNav .title {
  font-weight: 500;
  padding-top: 10px;
  padding-left: 10px;
}
.main {
  display: flex;
  flex-direction: column;
  justify-content: flex-start;
  width: 100%;
}
.main .messagesListContainer {
  flex: 1;
  display: flex;
  flex-direction: column;
  justify-content: flex-end;
}
.main .messagesList {
  padding: 5px;
}
.main .newMessage {
  width: 100%;
}
.messagesList {
  max-height: 450px;
  overflow: auto;
}
.messagesEntry {
  margin: 5px;
  border-bottom: 1px solid black;
}
<div class="app">
        <div class="leftNav">
          <div class="title"> Channels </div>
          <div>
            Channel 1
          </div>
          <div>
            Channel 2
          </div>
        </div>
        <div class="main">
          <div class="bar">
            <Navbar>
              Navbar goes here
            </Navbar>
          </div>
          <div class="messagesListContainer">
            <div class="messagesList">
              What is Lorem Ipsum?
Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.

Why do we use it?
It is a long established fact that a reader will be distracted by the readable content of a page when looking at its layout. The point of using Lorem Ipsum is that it has a more-or-less normal distribution of letters, as opposed to using 'Content here, content here', making it look like readable English. Many desktop publishing packages and web page editors now use Lorem Ipsum as their default model text, and a search for 'lorem ipsum' will uncover many web sites still in their infancy. Various versions have evolved over the years, sometimes by accident, sometimes on purpose (injected humour and the like).

Where does it come from?
Contrary to popular belief, Lorem Ipsum is not simply random text. It has roots in a piece of classical Latin literature from 45 BC, making it over 2000 years old. Richard McClintock, a Latin professor at Hampden-Sydney College in Virginia, looked up one of the more obscure Latin words, consectetur, from a Lorem Ipsum passage, and going through the cites of the word in classical literature, discovered the undoubtable source. Lorem Ipsum comes from sections 1.10.32 and 1.10.33 of "de Finibus Bonorum et Malorum" (The Extremes of Good and Evil) by Cicero, written in 45 BC. This book is a treatise on the theory of ethics, very popular during the Renaissance. The first line of Lorem Ipsum, "Lorem ipsum dolor sit amet..", comes from a line in section 1.10.32.
            </div>

            <form>
              <div>
                <input placeholder='input' />
              </div>
            </form>
          </div>
        </div>
      </div>

Upvotes: 0

Views: 245

Answers (1)

Nikhil Kinkar
Nikhil Kinkar

Reputation: 781

As you said you are trying to make slack like app, so I have considered your top navbar and input at bottom will be fixed.

here I have added

  • height: 100vh to .app as it is the wrapper to you application,
  • overflow: auto to the .main .messagesListContainer which makes the inner content scroll able.

this should solve your problem.

* {
  font-size: 16px;
  margin: 0;
  padding: 0;
}

.app {
  display: flex;
  flex-direction: row;
  height:100vh;
}

.leftNav {
  border-right: 1px solid black;
  width: 17%;
  padding: 0px;
  margin: 0;
  background-color: lightslategray;
  color: white;
}

.leftNav .title {
  font-weight: 500;
  padding-top: 10px;
  padding-left: 10px;
}

.main {
  display: flex;
  flex-direction: column;
  justify-content: flex-start;
  width: 100%;
}

.main .messagesListContainer {
  flex: 1;
  display: flex;
  flex-direction: column;
  justify-content: flex-end;
  overflow: auto;
}

.main .messagesList {
  padding: 5px;
}

.main .newMessage {
  width: 100%;
}

.messagesList {
  max-height: 450px;
  overflow: auto;
}

.messagesEntry {
  margin: 5px;
  border-bottom: 1px solid black;
}
<div class="app">
  <div class="leftNav">
    <div class="title"> Channels </div>
    <div>
      Channel 1
    </div>
    <div>
      Channel 2
    </div>
  </div>
  <div class="main">
    <div class="bar">
      <Navbar>
        Navbar goes here
      </Navbar>
    </div>
    <div class="messagesListContainer">
      <div class="messagesList">
        What is Lorem Ipsum? Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type
        specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more
        recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum. Why do we use it? It is a long established fact that a reader will be distracted by the readable content of a page when looking at its layout. The
        point of using Lorem Ipsum is that it has a more-or-less normal distribution of letters, as opposed to using 'Content here, content here', making it look like readable English. Many desktop publishing packages and web page editors now use Lorem
        Ipsum as their default model text, and a search for 'lorem ipsum' will uncover many web sites still in their infancy. Various versions have evolved over the years, sometimes by accident, sometimes on purpose (injected humour and the like). Where
        does it come from? Contrary to popular belief, Lorem Ipsum is not simply random text. It has roots in a piece of classical Latin literature from 45 BC, making it over 2000 years old. Richard McClintock, a Latin professor at Hampden-Sydney College
        in Virginia, looked up one of the more obscure Latin words, consectetur, from a Lorem Ipsum passage, and going through the cites of the word in classical literature, discovered the undoubtable source. Lorem Ipsum comes from sections 1.10.32 and
        1.10.33 of "de Finibus Bonorum et Malorum" (The Extremes of Good and Evil) by Cicero, written in 45 BC. This book is a treatise on the theory of ethics, very popular during the Renaissance. The first line of Lorem Ipsum, "Lorem ipsum dolor sit
        amet..", comes from a line in section 1.10.32.
      </div>

      <form>
        <div>
          <input placeholder='input' />
        </div>
      </form>
    </div>
  </div>
</div>

Upvotes: 2

Related Questions