gpt4 book ai didi

html - 如何以表格形式对齐div标签内的文本

转载 作者:行者123 更新时间:2023-11-28 15:53:32 25 4
gpt4 key购买 nike

我的文本后跟 (:) 冒号没有对齐。任何人都可以帮助我对齐它们。

<div>
<h4> Candidate Name :</h4>
<h4> Branch :</h4>
<h4> Position:</h4>
<h4> Reference Name :</h4>
<h4> Reference Phone # :</h4>
<h4> Reference Company :</h4>
<h4> Reference Job Title:</h4>
<h4> Relationship to Employee:</h4>
</div>

Current Output:

enter image description here

Requested Output:

enter image description here

最佳答案

这看起来像表格数据,因此在这种情况下您可以使用 CSS 表格布局

div {
display: table;
}
h4 {
display: table-row;
}
h4 span {
display: table-cell;
}
<div>
<h4> Candidate Name <span>: Random data</span></h4>
<h4> Branch <span>: Lorem</span></h4>
<h4> Position <span>: Lorem ipsum dolor</span></h4>
<h4> Reference Name <span>: Random data</span></h4>
<h4> Reference Phone # <span>: Random data</span></h4>
<h4> Reference Company <span>: Random data</span></h4>
<h4> Reference Job Title <span>: Random data</span></h4>
<h4> Relationship to Employee <span>: Random data</span></h4>
</div>

或者您可以更改 HTML 并仅使用表格

<table>
<tr> <td>Candidate Name </td> <td>: Random data</td></tr>
<tr> <td>Branch</td> <td>: Lorem</td></tr>
<tr> <td>Position </td><td>: LOrem ipsum dolor</td></tr>
<tr> <td>Reference Name </td> <td>: Random data</td></tr>
<tr> <td>Reference Phone #</td> <td>: Random data</td></tr>
<tr> <td>Reference Company</td> <td>: Random data</td></tr>
<tr> <td>Reference Job Title</td> <td>: Random data</td></tr>
<tr> <td>Relationship to Employee </td><td>: Random data</td></tr>
</table>

关于html - 如何以表格形式对齐div标签内的文本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38076963/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com