0

I have a line of text that contains multiple span elements. Example:

<div class="line">
    <span class="username">mario_sunny: </span><span class="message">Hello would you like to buy a <span class="item">Match</span>?</span>
</div>

The problem is when I try to create this in Java using GWT's InlineLabel or InlineHTML, it trims the leading/trailing spaces within the span, as you can see here:

enter image description here

How do I prevent this?

Here is my code:

HorizontalPanel lineLabel = new HorizontalPanel();
InlineHTML usernameLabel = new InlineHTML();
InlineLabel messageLabel = new InlineLabel();

lineLabel.setStyleName("chat-line");

usernameLabel.setStyleName("chat-username");
usernameLabel.setText("mario_sunny: ");

messageLabel.setText("Hello would you like to buy a Match?");

lineLabel.add(usernameLabel);
lineLabel.add(messageLabel);
mario_sunny
  • 1,412
  • 11
  • 29
  • See this: [HTML/CSS - Best practice for preserving white space on certain elements?](https://stackoverflow.com/questions/8994516/html-css-best-practice-for-preserving-white-space-on-certain-elements) – Adam Aug 08 '17 at 17:40
  • It's GWT that is removing the whitespace, not HTML. On pure HTML the whitespace renders fine. But GWT removes it. I want to use GWT but also preserve the whitespace. – mario_sunny Aug 08 '17 at 18:02
  • In GWT 2.7 that I use, the space is still present in the output markup. `white-space: pre;` makes it clearly visible. Also changing `HorizontalPanel` (rendered as ``) to `FlowPanel` (rendered as `
    `) helps, but I don't know if that would be acceptable.
    – Adam Aug 08 '17 at 18:11
  • Oh. I assumed it was GWT. I will try that. Thanks. – mario_sunny Aug 08 '17 at 23:26

0 Answers0