2016-06-28 54 views
-1

我有文本后跟(:)冒号未对齐。任何人都可以帮助我调整它们。如何以表格形式对齐div标记内的文本

<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> 

电流输出:

enter image description here

请求的输出:

enter image description here

+1

你需要更多的解释自己。张贴想要的结果的图像。 –

+0

这就是所需的效果! – Pugazh

回答

5

这看起来像表格数据,因此在这种情况下,你可以使用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>

0

div { 
 
    display: inline-block; 
 
} 
 
#values h4:before { 
 
    content: ': '; 
 
}
<div id="labels"> 
 
    <h4>Candidate Name</h4> 
 
    <h4>Date Completed</h4> 
 
    <h4>Branch</h4> 
 
    <h4>Position</h4> 
 
    <h4>Reference Name</h4> 
 
    <h4>Reference Phone #</h4> 
 
    <h4>Reference Company</h4> 
 
    <h4>Reference Title</h4> 
 
    <h4>Relationship to Employee</h4> 
 
</div> 
 
<div id="values"> 
 
    <h4>Name</h4> 
 
    <h4>11/11/1111</h4> 
 
    <h4>Mississigua</h4> 
 
    <h4>Salesforce Developer</h4> 
 
    <h4>John Smith</h4> 
 
    <h4>(416) 563-8888</h4> 
 
    <h4>Ocean Trailer</h4> 
 
    <h4>Service Manager</h4> 
 
    <h4>Direct Supervisor</h4> 
 
</div>

0
<div style="width: 200px"> 
    <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> 

h4 { 
    float: right; 
}