2011-12-05 77 views
1

我正在尝试创建类似于yahoo.com的东西,其中内容位于中间位置,郊外有一个灰色边距(或者至少看起来像一个边距,不确定它是否是填充)。我成功了,但是当页面被用户调整大小时,我希望这个页边距可以像在yahoo.com上一样减小,但不会减小(转到www.yahoo.com并调整页面大小并调整页边距)。任何人都知道如何让这个边际减少?随着窗口尺寸减小,边距减少

body 
{ 
    font-family: "Lucida Grande", "Lucida Sans"; 
    background-color: #525252; 
    text-align: center; 
    margin-left: 150px; 
    margin-right: 150px; 
    margin-top: 0px; 
    margin-bottom: 0px; 
    min-width: 650px; 
    min-height: 685px; 
    color: #00008B;  
} 

table 
{ 
    margin:0; 
    padding: 0px 2px; 
    border-spacing: 0; /* remove the spacing between the borders. */ 
    width: 950px; 
    height: 685px; 
    background-color: #C1CDC1; 
} 

回答

4

关键是你的身体标记的内容中创建固定宽度的div容器和边距设置为自动。

body { 
text-align: center; 
} 
div#container { 
width: 960px; 
text-align: left; 
margin: 0 auto 
} 

我还可以推荐萤火虫或类似的东西作为一个有用的工具来检查,除其他之外,网站的CSS和HTML?

+0

我也不得不放在身体:margin-left:auto; margin-right:auto;不知道为什么,但当我做到了,它完美的工作。 –

1

你的身体改变风格:

body { 
    font-family: "Lucida Grande", "Lucida Sans"; 
    background-color: #525252; 
    text-align: center; 
    margin: 0px auto 0px auto; 
    width: 650px; 
    min-height: 685px; 
    color: #00008B;  
}