简体   繁体   English

有没有办法使表格行与最高表格行具有相同的高度

[英]Is there a way to make table rows the same height as the highest table row

I was trying to make table rows all the same height as the highest element, without a fixed value.我试图使表格行的高度与最高元素的高度相同,但没有固定值。 With height auto the elements are all different height and a defined value isn't a good choice because the text of the row with much height is really unsteady.使用高度自动,元素都是不同的高度,并且定义的值不是一个好的选择,因为具有很多高度的行的文本确实不稳定。

Description of the problem as image:问题描述为图片: 在此处输入图片说明

Style + how I make the table:风格+我如何制作桌子:

.Tright {
    width: 33%;
    height: auto;
    float: right;
}

 <table class="Tright" > 
  <tr>
    <th>Nachname:</th>
    <td><?php echo $data['Nachname']; ?></td>
  </tr><tr>
    <th>Funktion:</th>
    <td><?php echo $data['Funktion']; ?></td>
  </tr><tr>
    <th>Funktionsbezeichnung:</th>
    <td><?php echo $data['Funktionsbezeichnung']; ?></td>
  </tr><tr>
    <th>Telefonnummer:</th>
    <td><?php echo $data['Telefonnummer']; ?></td>
  </tr><tr>
    <th>E-Mail:</th>
    <td><?php echo $data['E-Mail']; ?></td>
  </tr><tr>
    <th>Beschreibung:</th>
    <td><?php echo $data['Beschreibung']; ?></td>
  </tr>

</table>

Thanks for your help!谢谢你的帮助!

Copy this JavaScript code into your file and everything will work fine provided you have used and tags in your code.将此 JavaScript 代码复制到您的文件中,如果您在代码中使用了 和 标记,一切都会正常工作。 And also need to connect jQuery with your file as I had to use some jQuery in between.并且还需要将 jQuery 与您的文件连接,因为我必须在两者之间使用一些 jQuery。 Use this to add it in head section-使用它在头部部分添加它 -

<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>


var rows1 = [];
    var table = document.getElementsByTagName("table")[0];
    var rows = table.getElementsByTagName("tr");
    for (i = 0; i < rows.length; i++) {
        rows1.push($(rows[i]).height());
    }
    var max = rows1.reduce(function(a, b) {
    return Math.max(a, b);
}, 0);
        document.getElementsByTagName("body")[0].innerHTML = "<style>table tr { height: " + max + "px !important; }</style>" + document.getElementsByTagName("body")[0].innerHTML;

I hope it helps as it took me half hour to make this code.我希望它有所帮助,因为我花了半个小时来制作这段代码。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM