Techie Tips
| prevent span from breaking a line: the solution |
| Written by prettynerd |
| Tuesday, 20 October 2009 15:49 |
|
it took me decades to solve this problem only to know how simple it should have been. in a jsp web application i've been working on, i needed to show a lesson's attachments with image and it's complete file name on three browsers - ie, firefox and safari. i thought everything is working fine until our qa tester sent me the bug. unlike in firefox and safari, the attachments in ie were not in place. here are screenshots of what i am blabbering about:
safari:
ie:
incompatibility of ie browser is not new to me but i guess it is the hardest & most tidious job in front-end web development - that is, to develop an application to appear exactly the same as on all browsers! the screenshots above has the following code:
my first move was asking google "how a span works". google and i have been friends for so long now and i say that he is a genius and is the smartest friend i ever have. ehehe. i mistakenly believed that span element prevents a group of text from breaking up and a lot of google's recommendations believed it too. however, this is not always the case. take my bug for example - a span inside a div with less width. my search did not make sense and so i have to think of other ways to identify what was going wrong. so, instead of asking google what a span does, i figured asking "how will i prevent a line to break". asking google again, he took me to the www.w3.org. there it was - the answer to my question! w3 html 4.01 specification section 9.3.2:
Sometimes authors may want to prevent a line break from occurring between two words. The entity (  or  ) acts as a space where user agents should not cause a line break.
w3 html 4.01 specification section 9.3.3:
In HTML, there are two types of hyphens: the plain hyphen and the soft hyphen. The plain hyphen should be interpreted by a user agent as just another character. The soft hyphen tells the user agent where a line break can occur. The plain hyphen is represented by the "-" character (- or -). The soft hyphen is represented by the character entity reference ­ (­ or ­).
in his page "line breaks and the hyphen", jonathan snook solved my problem. i just had to add a style attribute on my span tag, as follows:
|




