2013-04-12 51 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