Html CSS是一个网页问题

Html CSS是一个网页问题,html,css,Html,Css,我无法使用css将网页居中: CSS代码如下: #wrapper { margin-left:auto; margin-right:auto; width: 100px; } #welcome { position:absolute; top:202px; width:560px; height:224px; z-index:2; } #newsSection { position:absolute; left:576px;

我无法使用css将网页居中:

CSS代码如下:

#wrapper {
  margin-left:auto;
  margin-right:auto;
  width: 100px;
}

#welcome {
    position:absolute;
    top:202px;
    width:560px;
    height:224px;
    z-index:2;
}
#newsSection {
    position:absolute;
    left:576px;
    top:209px;
    width:380px;
    height:600px;
    z-index:2;
}
HTML:


//满足于此
//满足于此
除了#News Section div,我可以将网页居中放置

我之所以将“left:576px”放在#newsSection div下,是因为我想将其放在#welcome div(并排)的旁边。然而,当我缩小浏览器大小时,#newsSection div将向左移动一点,并重叠#welcome div.
如果我删除“left:57px”,那么#newsSection div将显示在#welcome div…的右上方

请帮忙。
谢谢

这可能是因为您在child div上使用了绝对位置。因此,“孩子们会疯掉的”,比如,他们不在乎父div#wrapper是中心

一些潜在代码:


#wrapper {
  margin-left:auto;
  margin-right:auto;
  width: 100px;
}

#welcome {
    float: left;
    width:560px;
    height:224px;
}
#newsSection {
    float: left;
    width:380px;
    height:600px;
}

您应该使用相对定位,即tagname.class{position:relative;top/right:?;}

要使网页居中,您可以使用以下方法:

.container{
宽度:100%;
最大宽度:80%;
保证金:0自动;

}
好的,我移除aboslute位置。现在,一切都在中间,很好,但是,#新闻部分div出现在下面#欢迎div。我希望它出现在它旁边。我怎么做?只是添加了一些潜在的代码(不完全确定你希望它看起来如何,但这是我最好的猜测。很高兴听到。作为帮助其他有类似问题的人的提示,如果它对你有用,你应该将这篇文章标记为答案。
宽度:100%;最大宽度:80%;
是胡说八道。你不妨设置
宽度:80%

#wrapper {
  margin-left:auto;
  margin-right:auto;
  width: 100px;
}

#welcome {
    float: left;
    width:560px;
    height:224px;
}
#newsSection {
    float: left;
    width:380px;
    height:600px;
}