简体   繁体   English

如何使容器充满整个窗口?

[英]How can I make a container fill the entire window?

I have a main container in CSS that contains all divs for the page. 我在CSS中有一个主容器,其中包含该页面的所有div。 However, there is a white space of 8px pushing the entire container to the left. 但是,有一个8px的空白将整个容器推向左侧。 Any idea how I can get rid of it, and have the container fit the entire window without white space? 知道如何摆脱它,并使容器适合整个窗口而没有空白吗? If I use "margin-left: -8px" it just creates 8 pixels of white space on the right. 如果我使用“ margin-left:-8px”,它将在右侧创建8像素的空白。 Heres the code for the container: 这是容器的代码:

#container {
height: 100%;
width: auto;
position: relative;
background-color: #E6E6E6;
min-width: 960px;
}

Just set margin: 0px; 只需设置margin: 0px; on #container , if that does not work you can set #container ,如果不起作用,可以设置

body {
margin: 0px;
padding: 0px;
}

This is because of the default styles being applied by the browser stylesheet. 这是因为浏览器样式表应用了默认样式。


There are a few ways you can solve you're problem: 有几种方法可以解决您的问题:

Apply this css rule, which effectively get's rid of any default padding or margin applied to elements. 应用此css规则,该规则将有效地消除应用于元素的任何默认填充或边距。

* {
    margin: 0;
    padding: 0;
}

Or you could use a css reset stylesheet, which I recommend the most because different browsers handle elements somewhat differently and you want to even the field out so you don't run into any problems later. 或者,您可以使用css reset样式表,这是我最推荐的样式表,因为不同的浏览器对元素的处理略有不同,并且您希望对字段进行平均处理,这样以后就不会遇到任何问题。 I recommend Eric Mayers css reset stylesheet it can be found here: http://meyerweb.com/eric/tools/css/reset/ and I use it for my own projects. 我推荐Eric Mayers CSS重置样式表,可以在以下位置找到它: http : //meyerweb.com/eric/tools/css/reset/ ,我将其用于自己的项目。

html, body, #container {margin:0; min-height:100%;} 

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

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