html - 当其中一个单元格中有多于一行文本时,单元格内联边框不会拉伸(stretch)

标签 html css

我有一张由 div 制成的 table 。当每个单元格只有一行文本时它工作正常,但是,当其中一个单元格中有更多文本时,麻烦就开始了。该单元格中的文本被换行成多行,该单元格的行内边框被拉伸(stretch),但所有其他单元格都完好无损。 html代码是:

div {
  box-sizing: border-box;
  -moz-box-sizing: border-box;
  -webkit-box-sizing: border-box;
}
.container {
  display: table;
  border-collapse: collapse;
  vertical-align: middle;
  width: 100%;
}
.trow {
  width: 100%;
  display: table-row;
  border: 1px solid;
}
.trow1 {
  width: 100%;
  display: table-row;
  border: 1px solid;
  text-align: center;
}
.tcell {
  float: left;
  display: table-cell;
  border-right: 1px solid;
}
<div class="container">
  <div class="trow1">
    <div class="tcell" style="line-height: 35px; width:30%; height:40px;">Left Stuff</div>
    <div class="tcell" style="line-height: 35px; width:40%; height:40px;">Middle Stuff</div>
    <div class="tcell" style="line-height: 35px; width:30%; height:40px;">Right Stuff</div>
    <br style="clear: left;" />
  </div>
  <div class="trow">
    <div class="tcell" style="width:25%;">Left Stuff</div>
    <div class="tcell" style="width:40%;">Middle Stuff</div>
    <div class="tcell" style="width:25%;">Right Stuff</div>
    <div class="tcell" style="width:10%;">R-Right StuffR-Right StuffR-Right StuffR-Right StuffR-Right StuffR-Right Stuff</div>
    <br style="clear: left;" />
  </div>
</div>

请指教我该怎么做。 TIA。

最佳答案

你可以为trowtrow1设置display:table,然后显示你想要的样子:

div {
  box-sizing: border-box;
  -moz-box-sizing: border-box;
  -webkit-box-sizing: border-box;
}
.container {
  display: table;
  border-collapse: collapse;
  vertical-align: middle;
  width: 100%;
}
.trow {
  width: 100%;
  display: table;
  border: 1px solid;
}
.trow1 {
  width: 100%;
  display: table;
  border: 1px solid;
  text-align: center;
}
.tcell {
  display: table-cell;
  border-right: 1px solid;
}
<div class="container">
  <div class="trow1">
    <div class="tcell" style="line-height: 35px; width:30%; height:40px;">Left Stuff</div>
    <div class="tcell" style="line-height: 35px; width:40%; height:40px;">Middle Stuff</div>
    <div class="tcell" style="line-height: 35px; width:30%; height:40px;">Right Stuff</div>
  </div>
  <div class="trow">
    <div class="tcell" style="width:25%;">Left Stuff</div>
    <div class="tcell" style="width:40%;">Middle Stuff</div>
    <div class="tcell" style="width:25%;">Right Stuff</div>
    <div class="tcell" style="width:10%;">R-Right StuffR-Right StuffR-Right StuffR-Right StuffR-Right StuffR-Right Stuff</div>
  </div>
</div>

关于html - 当其中一个单元格中有多于一行文本时,单元格内联边框不会拉伸(stretch),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41995641/

相关文章:

php - 连接 Facebook 按钮 - 弹出窗口如何工作?

css - 无法理解带有图形标签 HTML5 的空间要求

javascript - 查看网站图片下载进度?

javascript - 如何拆分 Javascript 和 HTML 文件?

html - 如何将文本居中放置在响应式圆圈的中间,(文本也是响应式的)?[仅限 css/html]

javascript - 有什么方法可以对客户端用户隐藏 CSS 和 JavaScript 文件?

javascript - jQuery .click() 无法正常工作

jQuery 悬停在一个 div 上

javascript - 如何更改转换 :translate css rule according to the screen resolution?

javascript - 只打印 <div id ="printarea"></div>?