简体   繁体   English

为什么即使高度为100%,高度为100vh,也无法获得完整的页面?

[英]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. 我正在构建一个看起来像Slack的简单Web应用程序,我在使页面占据整个宽度和高度时遇到问题。 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%. 问题在于它实际上要花一半的时间才能结束,而其他时间要花更长的时间,但左侧导航栏的尺寸却不一样,左侧导航的顶部60%与底部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. 我已经包含了代码片段,我添加了几个参数'height:100%'和'height:100vh'并将它们添加到*,html和body中,但总是以某种方式转为不正确的内容。

 * { 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> 

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. 正如您所说,您正尝试使应用程序像松弛一样,因此我考虑了顶部navbar ,底部的input将固定。

here I have added 在这里我加了

  • height: 100vh to .app as it is the wrapper to you application, height: 100vh .app height: 100vh ,因为它是应用程序的包装,
  • overflow: auto to the .main .messagesListContainer which makes the inner content scroll able. overflow: auto转到.main .messagesListContainer ,使内部内容能够滚动。

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> 

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 为什么 100% 或 100vh 高度没有占据整个页面高度 - why 100% or 100vh height not occupying full page height 在不使用100vh的情况下将div强制设为完整页面高度 - Forcing a div to be full page height without using 100vh 车身高宽为100vh; 并且其中的 div 宽度为 100vh 或 100% 但它没有接触边缘?为什么 - Body height and width is 100vh; and the div in this has width 100vh or 100% but it is not touching the edge ?why 如何在高度为 100Vh 的页面上添加 100vh header 图像? - How to add a 100vh header image on a page with a height of 100Vh? 使用 100vh 并具有居中内容的 HTML 全高英雄 - HTML full height hero using 100vh with centered content 为什么使用100vh作为高度后组件没有拉伸到web页面的高度 - Why is the component not stretching to the height of the web page after using 100vh as the height 将 100vh 高度页面中的元素向上滚动并移出视图 - Scroll elements in a 100vh height page up and out of view 页面上的3个元素,总共100vh,一个高度未知 - 3 elements on page, 100vh altogether, one height unknown ```高度:100vh```和页面底部的白色边距的意外行为 - Unexpected behavior with ```height: 100vh``` and white margin at the bottom of the page 为什么这个高度为100vh的div无法覆盖整个视口? - Why is this div with 100vh height not covering the whole viewport?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM