Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Correct word wrap in a span tag

I've a form with an inline validation message in a span.

<span id="EndTimeErrors">
  <label for="EndTime" class="field-validation-error">
      Bitte geben Sie eine gültige Uhrzeit ein, zum Beispiel 8:00 oder 14:34
  </label>
</span>

Ugly wrap with span

Unfortunately the word wrap is really ugly. I could put the validation message in a div, to beautify the message. The result is better, but not perfect.

<div id="EndTimeErrors">
  <label for="EndTime" class="field-validation-error">
      Bitte geben Sie eine gültige Uhrzeit ein, zum Beispiel 8:00 oder 14:34
  </label>
</div>

Using a div

What I really want is something like this:

Mockup of goal

What CSS code would you use to achieve the desired result?

like image 369
Sandra Avatar asked Feb 10 '10 15:02

Sandra


2 Answers

Try

white-space: nowrap;
like image 145
wawooca Avatar answered Sep 24 '22 01:09

wawooca


Here is the code I ended up with:

<span id="EndTimeErrors" style="position: absolute; left: 300px;">
  <label for="EndTime" class="field-validation-error">
      Bitte geben Sie eine gültige Uhrzeit ein, zum Beispiel 8:00 oder 14:34
  </label>
</span>

I positioned the span absolutely and moved it 300px to the left.

This works, but I'm not totally satisfied with this solution, because the 300px are hard-coded. If the length of stuff in front of the validation message would change, I would also need to change the 300px.

like image 27
Sandra Avatar answered Sep 26 '22 01:09

Sandra