2013-04-12 47 views
1

我发现了一些代码,可以创建带有页眉和页脚的完美的两列布局。无论内容如何,​​这两列都可以完美地展现出来,这正是我所追求的目标。两列,等高布局 - 列间空格

问题:我找不到在两列之间创建空间的方法。我需要空间,因为我正在使用边框,而且看起来过于狭窄。这些列没有浮动,利润率也没有成功。

任何人都可以想到在不破坏功能的情况下分离两者的方法吗?

这里是的jsfiddle链接:http://jsfiddle.net/7M9rg/3/

非常感谢!

下面是代码:

<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;} 

回答

1

由于您使用display: table-cell,利润率不工作。

这是一个工作。创建一个隔离板,如下,并插入#side#content之间:

<hr class="spacer"> 

样式新元素为:

hr.spacer { 
    display: table-cell; 
    border: 1px; 
    width: 10px; 
} 
将宽度设置为一个合适的值。

小提琴:http://jsfiddle.net/audetwebdesign/navc5/

这引入了额外的元素,但它很容易实现和可靠。

请注意,IE7及更早版本不支持table-cell。对于一些人来说,这是一个问题。

0

因为您的元素现在实际上是一个表格,所以您可以使用适用于表格的所有属性。 border-spacing属性是你要找的,它适用于元素。

http://jsfiddle.net/7M9rg/6/

#main { 
    border-spacing: 10px; 
} 

你需要做修修补补周围的元素,让您的#main元素回到位置,它应该是利润率的一个位。

+0

这很有趣;我刚碰到一篇关于border-spacing的文章,但将它应用于错误的div。现在已经将它应用于#main,并且正在按照我希望的方式执行 - 非常感谢您的快速响应! – user2275661