简体   繁体   English

为什么容器不占据整个高度

[英]Why doesn't container take up entire height

I'm trying to make survey form page.我正在尝试制作调查表格页面。 I have made div with id="container" which contains every element on my site.我用 id="container" 制作了 div,其中包含我网站上的每个元素。 Code Below and there https://codepen.io/pawe-micho/pen/GRoLJLY?editors=1100代码如下https://codepen.io/pawe-micho/pen/GRoLJLY?editors=1100

CODE代码

 * { margin: 0; padding: 0; box-sizing: border-box; } html, body { height: 100%; color: #black; background-color: #202020; } #container { height: 100%; max-width: 650px; margin: 0 auto; background-color: #fff; }
 <div id="container"> <header id="title"> <h1>Software World</h1> <p id="Description">Entertainment which creates software for people</p> </header> <form action="send_it_somewhere.html" id="survey-form" method="POST"> <div class="input-div"> <label for="name" id="name">Name</label> <input type="text" id="name" name="name" required> </div> <div class="input-div"> <label for="email" id="email">E-mail</label> <input type="email" id-"email" name="email" required> </div> <div class="input-div"> <label for="age" id="age">Age</label> <input type="number" id="age" name="age" min="1" max="100"> </div> <div class="input-div"> <label for="dropdown">How do you want to pay</label> <p>(Hold ctrl and click to tick multiple)</p> <select name="dropdown" id="dropdown"> <option value="all">All at once</option> <option value="months12">12 months</option> <option value="months6">6 months</option> <option value="Other">Other</option> </select> </div> <div class="input-div"> Gender <div> <label for="male">Male</label> <input type="radio" name="gender" id="male" value="male"> <label for="female">Female</label> <input type="radio" name="gender" id="female" value="female"> </div> </div> <div class="input-div"> <p>What would you like to have in your software</p> <label for="pc_system">Access on PC</label> <input type="checkbox" name="pc_system" id="pc_system" value="pc_system"> <div class="blank-div"></div> <label for="android-system">Access on Android</label> <input type="checkbox" name="android-system" id="android-system" value="android-system"> <div class="blank-div"></div> <label for="ios-system">Access on IOS</label> <input type="checkbox" name="ios-system" id="io-system" value="ios-system"> <div class="blank-div"></div> <label for="online_mode">Online Mode</label> <input type="checkbox" name="online_mode" id="online_mode" value="online_mode"> <div class="blank-div"></div> <label for="payment">Payment</label> <input type="checkbox" name="payment" id="payment" value="payment"> <div class="blank-div"></div> <label for="making_accounts">Option of making accounts</label> <input type="checkbox" name="making_accounts" id="making_accounts" value="making_accounts"> <div class="blank-div"></div> <label for="support">24/7 Support</label> <input type="checkbox" name="support" id="support" value="support"> <div class="blank-div"></div> </div> <div class="input-div"> <label for="question">Ask a question</label> <textarea name="question" id="question"></textarea> </div> <button type="submit">Submit</button> <button type="reset">Reset</button> </form> </div>

I want a container to be a big white stripe which takes entire height of html, but as you can see below, not whole container has got white background.我想要一个容器是一个大的白色条纹,它占据了 html 的整个高度,但正如你在下面看到的,不是整个容器都有白色背景。

picture which shows container doesnt take whole height显示容器不占整个高度的图片

I only want a picture with entire height of website whole time, I mean container should maintain entire height when It is fullscreen too.我只想要整个网站整个高度的图片,我的意思是容器在全屏时也应该保持整个高度。

enter code here

U just need to disable min-height:100vh;你只需要禁用 min-height:100vh;

Try removing the height:100%;尝试删除高度:100%; on the html tag在 html 标签上

try this.尝试这个。

body {
  color: #black;
  background-color: #202020;
}

#container {
  height: 100%;
  max-width: 650px;
  margin: 0 auto;
  background-color: #fff;
}

I think problem was you were setting html,body.我认为问题是您正在设置 html,body。 In this case it's enough to set just background-color for body of your page.在这种情况下,只需为页面正文设置背景颜色就足够了。

TIP: Dont use ID for styling.提示:不要使用 ID 进行样式设置。 ID is mostly used in JavaScript or other programming languages. ID 多用于 JavaScript 或其他编程语言。 For styling use classes.对于样式使用类。

You could do this as well:你也可以这样做:

 * { margin: 0; padding: 0; box-sizing: border-box; } html, body { color: #black; background-color: #202020; }.input-div{ background-color: #fff; } #container { height: 100vh; max-width: 650px; margin: 0 auto; background-color: #fff; }
 <div id="container"> <header id="title"> <h1>Software World</h1> <p id="Description">Entertainment which creates software for people</p> </header> <form action="send_it_somewhere.html" id="survey-form" method="POST"> <div class="input-div"> <label for="name" id="name">Name</label> <input type="text" id="name" name="name" required> </div> <div class="input-div"> <label for="email" id="email">E-mail</label> <input type="email" id-"email" name="email" required> </div> <div class="input-div"> <label for="age" id="age">Age</label> <input type="number" id="age" name="age" min="1" max="100"> </div> <div class="input-div"> <label for="dropdown">How do you want to pay</label> <p>(Hold ctrl and click to tick multiple)</p> <select name="dropdown" id="dropdown"> <option value="all">All at once</option> <option value="months12">12 months</option> <option value="months6">6 months</option> <option value="Other">Other</option> </select> </div> <div class="input-div"> Gender <div> <label for="male">Male</label> <input type="radio" name="gender" id="male" value="male"> <label for="female">Female</label> <input type="radio" name="gender" id="female" value="female"> </div> </div> <div class="input-div"> <p>What would you like to have in your software</p> <label for="pc_system">Access on PC</label> <input type="checkbox" name="pc_system" id="pc_system" value="pc_system"> <div class="blank-div"></div> <label for="android-system">Access on Android</label> <input type="checkbox" name="android-system" id="android-system" value="android-system"> <div class="blank-div"></div> <label for="ios-system">Access on IOS</label> <input type="checkbox" name="ios-system" id="io-system" value="ios-system"> <div class="blank-div"></div> <label for="online_mode">Online Mode</label> <input type="checkbox" name="online_mode" id="online_mode" value="online_mode"> <div class="blank-div"></div> <label for="payment">Payment</label> <input type="checkbox" name="payment" id="payment" value="payment"> <div class="blank-div"></div> <label for="making_accounts">Option of making accounts</label> <input type="checkbox" name="making_accounts" id="making_accounts" value="making_accounts"> <div class="blank-div"></div> <label for="support">24/7 Support</label> <input type="checkbox" name="support" id="support" value="support"> <div class="blank-div"></div> </div> <div class="input-div"> <label for="question">Ask a question</label> <textarea name="question" id="question"></textarea> </div>

I removed height from body and added a height using vh on container.我从正文中删除了高度,并在容器上使用 vh 添加了一个高度。 I think this is good because if you want to add more things to the body then you can use for each section the height you want.我认为这很好,因为如果您想为身体添加更多东西,那么您可以为每个部分使用您想要的高度。 Also in the html you have a container div and a input div.同样在 html 中,您有一个容器 div 和一个输入 div。 This last div that uses the class of 'input-div' is not inside the container div so when the height of the screen gets smaller it kinda "breaks".最后一个使用“input-div”的 class 的 div 不在容器 div 内,因此当屏幕高度变小时它有点“中断”。

Use height: auto instead of height: 100%;使用height: auto代替height: 100%; as height: 100% takes 100% of viewport but not content. as height: 100%占用视口的 100%,但不占用内容。 height: auto stretches and expands to fit all content. height: auto拉伸和扩展以适应所有内容。

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM