2014-03-31 45 views
2

您好我想打它从我希望把中间的一个内部大div结构的一个网页,我想让它变得中心,以便它看起来像一个margin:0 auto但有table自动调整表格中的外部单元格?

我不是很确定我应该怎么解释,但这里是我想要的表格看起来像一个例证:enter image description here

我想知道是否我应该使用Javascript或是否存在与CSS

回答

0
方式

最简单的方法是运用一个规律,一拉:

/* find the 2nd (middle) cell in the 2nd (middle) row */ 
.table .row:nth-child(2) .cell:nth-child(2){ 
    text-align:center; 
} 
/* find the div in this cell and align it */ 
.table .row:nth-child(2) .cell:nth-child(2) div{ 
    margin: 0 auto; 
    width:200px; /* example */ 
} 

.table.row.cell是适当的位置Y你正在使用。

另外...如果你使用这个页面布局,下面的代码如何处理,它有一个页眉,页脚和居中,拉伸内容,不需要表格,所以应该在传统浏览器中工作。

Demo Fiddle

HTML

<section> 
    <article></article> 
    <header></header> 
    <footer></footer> 
</section> 

CSS

html, body { 
    height:100%; 
    margin:0; 
    padding:0; 
    width:100%; 
} 
header, footer, article { 
    position:absolute; 
    width:100%; 
} 
header { 
    height:100px; 
    background:red; 
    top:0; 
} 
footer { 
    height:90px; 
    bottom:0; 
    background:green; 
} 
section { 
    position:relative; 
    height:100%; 
    background:grey; 
    text-align:center; 
    width:100%; 
} 
article { 
    padding-top:100px; 
    padding-bottom:90px; 
    margin:0; 
    width:500px; 
    background:blue; 
    margin:0 auto; 
    position:relative; 
    height:100%; 
    box-sizing:border-box; 
} 
相关问题