中心固定宽度/液体css布局,带显示:表格属性和最小/最大宽度

时间:2013-04-13 00:26:55

标签: css layout

目标是将此布局置于屏幕中心。我的最小宽度为600px,最大宽度为1200px,因此布局周围可能存在大量空白区域。

我一直在尝试很多不同的方法,但我对display:table属性以及它在这种情况下的行为方式感到困惑。

这是jsFiddle和代码:http://jsfiddle.net/7M9rg/6/

非常感谢您对此提出任何建议!

HTML:

<div id="wrapper">
<div id="header">
</div>

<div id="main">

<div id="side">
<div id="side-stuff">
<ul>
<li><a href="../English/index.html">Home</a></li>
</ul>
</div>
</div>

<div id="content">
<p>Contrary to popular belief, Lorem Ipsum is not simply random text. It has</p>
</div>
</div>

<div id="footer">&copy; 2013 </div>
</div>

CSS:

/*css reset*/
html,body {position:relative;margin:0;padding:0;min-height:100%;width:100%;
height:100%;}
div,p,dl,dt,dd,ul,ol,li,h1,h2,h3,h4,h5,h6,pre,form,fieldset,input,
textarea,p,blockquote,th,td, figure {margin:0;padding:0;}
ol,ul {list-style:none;}
li {list-style-type: none;}
* { -moz-box-sizing: border-box; -webkit-box-sizing: border-box; box-sizing:
border-box; }


html, body {
font-family: Helvetica;
height: 100%; /*important for equal height columns*/
min-width: 650px;
}

#wrapper{
height: 100%; /*important for equal height columns*/
padding-bottom:130px; /*This must equal the height of your header*/}

#header{
height: 130px; /*This must equal padding bottom of wrap*/
display:block;
padding: 5px;
color: #fff;
border: thin solid #ebebeb;
border-radius: 10px;
margin: 10px;
background-image: url(Images/gradient.png);
background-repeat: repeat-x;    
width: 99%;}

#main {
position: relative;
height: 100%; /*important for equal height columns*/
width: 99%;
overflow:auto;
display: table; /* This is needed fo children elements using display table cell*/
table-layout: fixed;
padding-bottom: 50px; /*This needs to match footer height*/
overflow: auto;
margin-left: 10px;}

#side{
background-color: #fff;
width: 150px;
margin: 10px;
vertical-align: top;
padding-top: 20px;
padding-right: 10px;
display: table-cell;
border-radius: 10px;
border: thin solid #CCC;}

#side-stuff{
display: block;
padding-left: 10px;}

#content{
background-color: #fff;
padding: 10px;
display: table-cell; /*To make sibling columns equal in height*/
margin-bottom:10px;
border-radius: 10px;
border: thin solid #CCC;}

#content-stuff{
width: auto;
height: auto;}

#footer{
position: relative;
height: 40px;
margin-top: -40px; /* margin-top is negative value of height */
margin-left: 10px;
clear: both; /* Use if floating elements */
color: #999;
width: 99%;
border: thin solid #ebebeb;
border-radius: 10px;
background-image: url(Images/footer_gradient.png);
background-repeat: repeat-x;
background-position: bottom;}

2 个答案:

答案 0 :(得分:1)

将此添加到#wrapper CSS:

max-width: 1200px;
margin: 0 auto;

http://jsfiddle.net/tshz6/

答案 1 :(得分:0)

您需要为<body>#wrapper元素指定宽度。 min-width仅指定可缩小的最小宽度,widthmax-width设置为auto,这是所有可用宽度(在这种情况下屏幕宽度)。 尝试将html, body规则更新为以下

html, body {
  font-family: Helvetica;
  height: 100%;
  margin: 0 auto;
  min-width: 650px;
  max-width: 1200px;
}