Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Adjust spaces between text or words in html

I have a problem is how adjust spaces between text or words in html. I want my result 2 "colon" alignment can adjust same line.

Below is my sample code:

<tr><td style="font-size:11px;">Name :</td></tr><br>
<tr><td style="font-size:11px;">Date &nbsp;<span style="word-spacing:80px;">:</span></td></tr>

Now my result alignment cannot be same like:

result

I want the expected result is same like below:

result_2

I have try to use <p> to replace <span> adjust the alignment, but the "Colon" will break down. Hope someone can guide me on how to solve this problem. Thanks.

like image 906
David Holly Avatar asked Nov 18 '25 19:11

David Holly


2 Answers

As the colon is for visual separation rather than having any meaning I would consider inserting it in a pseudo element rather than actually in the HTML.

This snippet puts the colon in just before the following td which ensures the colons are aligned.

td:nth-child(2)::before {
  content: ':';
}
<table>
  <tr>
    <td style="font-size:11px;">Name </td>
    <td></td>
  </tr><br>
  <tr>
    <td style="font-size:11px;">Date</td>
    <td></td>
  </tr>
</table>
like image 50
A Haworth Avatar answered Nov 21 '25 10:11

A Haworth


I had a similar problem and the only "hacky" way I found is this:
"Put your text and separator (: in this case) in a wrapper (like <div>) and align them.

.cell {
  display: flex;
  justify-content: space-between;
  width: 50px; /* just to see. you can use another value depending on your table styles */
}
<tr>
  <td style="font-size:11px;">
    <div class="cell">Name <span>:</span></div>
  </td>
</tr>
<tr>
  <td style="font-size:11px;">
    <div class="cell">Date <span>:</span></div>
  </td>
</tr>

Also, you don't need <br> between your table rows (<tr>s).

like image 23
Shahriar Avatar answered Nov 21 '25 08:11

Shahriar



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!