Strange indentation when using pre

In C# I fill a field with strings. Every string is ending with “rn”. Then I fill a website with this data using Razor:

<td style="max-width:130px; overflow-wrap:break-word; white-space:pre;"
     align="left">
     @item.Data
</td>

Output on the website:
          - first line     (about 13 additional empty spaces)
- second line
- third line
- fourth line and so on

Desired output:
- first line
- second line
- third line
- fourth line and so on

Should I provide more code?

EDIT:

HTML:

<td style="max-width:130px; overflow-wrap:break-word; white-space:pre;"
    align="left">
    firstline
secondline
</td>

Solution:
Actually my code maid extension in Visual Studio added white space after <td …>(many whitespace here)

Answers:

Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.

Method 1

The white spaces are generated by the “formatted” html source code.
You need to “uglify” the html code as well.

Before:

<tr>
    <td style="max-width:130px; overflow-wrap:break-word; white-space:pre;" align="left">
        firstline
secondline
    </td>
</td>

After:
<tr>
    <td style="max-width:130px; overflow-wrap:break-word; white-space:pre;" align="left">firstline
secondline</td>
</tr>

Method 2

Your text/code inside your white-space:pre;, should start at the beginning of the line (no tabs or spaces). I have given an example below.

<td style="max-width:130px; overflow-wrap:break-word; white-space:pre;"
    align="left">
firstline
secondline
</td>


All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0

0 0 votes
Article Rating
Subscribe
Notify of
guest

0 Comments
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x