css - 两列,等高布局 - 列之间的空间

标签 css layout multiple-columns

我发现一些代码可以创建带有页眉和页脚的完美两列布局。无论内容如何,​​这两列都完美地向下和向右延伸,这正是我一直在寻找的。

问题:我找不到在两列之间创建空间的方法。我需要空间,因为我正在使用边框,而且它看起来很局促。列不是 float 的,边距也不起作用。

有人能想出一种在不破坏功能的情况下将两者分开的方法吗?

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

最佳答案

因为您正在使用 display: table-cell,所以边距不起作用。

这是一种解决方法。如下创建一个分隔符,并在#side#content之间插入:

<hr class="spacer"> 

将新元素设置为:

hr.spacer {
    display: table-cell;
    border: 1px;
    width: 10px;
}

将宽度设置为合适的值。

fiddle :http://jsfiddle.net/audetwebdesign/navc5/

这引入了一个额外的元素,但它易于实现且可靠。

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

关于css - 两列,等高布局 - 列之间的空间,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15979328/

相关文章:

html - 如何在 'direction ltr' 段落中强制一段文本为 'direction rtl'

html - Materialise grid 做5列

html - 为 fontawesome 图标添加白色背景

android - 创建可滚动的图像按钮的 android 布局?

css - 将内容放在垂直导航旁边

css - 动态DIV高度

java - 当我为 JFrame 使用 FlowLayout 时,为什么我的图像没有出现?

html - CSS 列,从上到下然后从左到右

unix - 使用awk提取具有多个名称的列数据(UNIX)

html - 确保列以标题标记开头