2015-05-20 102 views
2

我只是试图让我的表行去跨表中的所有方法,但它仅在左侧填充约20%。获取表行跨越整个宽度

<table id="t1" style="width:25%; height:50%"> 
<tr id="tr1"> 
    <td id="user1"></td> 
    <td id="champ1"></td> 
    <td id="wr1"></td> 
</tr> 
</table> 

我在后面的脚本中的数据单元中的值。 这是CSS。

#t1 { 
    margin-left: auto; 
    margin-right: auto; 
    display: inline-block; 
} 
tr { 
    width: 100%; 
    align-content: center; 
} 
+1

为什么你​​元素与关闭? –

+0

糟糕,修正了这个问题。 – ghadams

回答

1

在您的代码中,您不需要关闭<td>'s,而是每个都在关闭</tr>中终止。如果在<td>没有内容,添加&nbsp;

表行(<tr>)将默认为表的100%,如果除去display: inline-block,并正确终止它们。把它们包裹起来,让它们浮起来。这使您有机会为表格添加标题或添加控件。

我建议的HTML:

<div class="wrapper"> 
    <div class="left"> 
    <table id="table1"> 
    <tr> 
     <td>&nbsp;</td> 
     <td>&nbsp;</td> 
     <td>&nbsp;</td> 
    </tr> 
    </table> 
    </div> 
    <div class="right"> 
    <table id="table2"> 
    <tr> 
     <td>&nbsp;</td> 
     <td>&nbsp;</td> 
     <td>&nbsp;</td> 
    </tr> 
    </table> 
    </div> 
</div> 

CSS:

的所有代码
/* Optionally throw in a media query, so the floats only happen if there is enough room for the two tables next to each other, but seamlessly fall under each other if not -- @media screen and (min-width: 600px){*/ 
.left{float:left; width:50%;} 
.right{float:right; width:50%;} 
/* } Optionally, close the media query here. */ 
/* Keep the wrapper open until both tables are done*/ 
.wrapper:after{clear:both;} 
table{} 
/* Add margin if the tables get to close, or negative margin if you want them closer*/ 
1

从#t1样式中删除display: inline-block

这也将导致表,因为汽车利润的中心,所以如果你想表左对齐删除这些。

例的jsfiddle:http://jsfiddle.net/Lrog2pgm/

+0

唯一的问题是,我有另一张桌子,我希望他们两个彼此相邻。 – ghadams

+0

使用float:left和float:right将它们并排放置。 – Steve

+0

Ahhhh工作。我不想让他们分开,所以我想我只会增加利润率? – ghadams

1

您的标记是一个烂摊子......

首先,你正在关闭<td></tr>

我不知道什么是align-content: center;?我想你的意思是text-align: center;

你正在共享一个#id 2选择器(ID = 'TR1')。不允许。

先尝试修复了一些这些东西。

+1

问题有ID tr1和t1。他们不是重复的。另外,看看align-content:http://www.w3schools.com/cssref/playit.asp?filename=playcss_align-content&preval=center –

+0

哦......我的不好。我现在看到了。可能要重新考虑你的命名约定,然后......这是非常模糊的,而且显然很容易被误解。此外,你真的应该使用类而不是ID。更好的重用性和扩展性。 –

0

首先是一个烂摊子。它有不匹配的标签,并且只是混杂在一起。其次,不要再次使用表格。它们几乎被弃用。这些日子你可以用列表完成你所做的一切。表甚至没有响应。就像你发现的那样,它们很有气质。我的回答:使用<ul>

+0

表格还活着。它们不打算用于布局目的,但对表格数据非常有效:http://www.w3.org/TR/html5/tabular-data.html。这个问题并没有说明表格的用途,所以它可能是语义上正确的标记。 –

相关问题