html - 使表格行跨越整个宽度

标签 html css

我只是想让我的表格行一直穿过表格,但它只填充左侧的大约 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;
}

最佳答案

在您的代码中,您没有关闭 <td>的,你们每个人都以结束 </tr> 结束反而。如果<td>中没有内容,添加&nbsp;

如果删除 <tr> ,表行 ( display: inline-block ) 将默认为表的 100% ,并正确终止它们。将它们包裹在一些东西中以使它们漂浮。这使您有机会为表格添加标题或添加控件。

我建议使用 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*/

关于html - 使表格行跨越整个宽度,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30339118/

相关文章:

javascript - 如何在javascript字符串之间附加一些东西?

javascript - 根据值更改 <select> 的颜色 - 仅限 CSS(?)

html - 在 float div 上绘制的 CSS 边框

javascript - 在容器上缩放 iOS 应用图像

html - 在 span 标签中居中对齐 SVG

html - 使用 CSS 强制文本超过 2 行

html - 向 View 中 rails 显示的文本添加一个类

css - 在不使用 z-index 的情况下指定 CSS 堆栈顺序

html - <h :selectOneMenu> dropdown list moving upwards in IE11

html - 撤消 CSS 规则以使表格行从列变回行