Search code examples
javahtmlspring-bootthymeleaf

Display address in single column instead of each line of address in its own column


I have a Thymeleaf template whth the following:

<td th:text="${tempUser.addressLine1}" />
<td th:text="${tempUser.addressLine2}" />
<td th:text="${tempUser.town}" />
<td th:text="${tempUser.county}" />
<td th:text="${tempUser.country}" />
<td th:text="${tempUser.postcode}" />

Each line of the address gets output to different column. How can I change this so my Entire address is displayed in a single column in the format:

Address Line 1
Address Line 2
Town
County
Country
Post Code

Solution

  • If you don't need tables you can do it like this

    .container {
      display: flex;
      flex-direction: column;
    }
    
    /*
    .container > span {
      display: block;
    }
    */
    <div class="container">
      <span th:text="${tempUser.addressLine1}"></span>
      <span th:text="${tempUser.addressLine2}"> </span>
      <span th:text="${tempUser.town}"> </span>
      <span th:text="${tempUser.county}"></span>
      <span th:text="${tempUser.country}"></span>
      <span th:text="${tempUser.postcode}"></span>
    </div>