4

It seems to me, that HTML entity for nonbreaking space is not working properly in my code. I use: zvyšováním ceny – ta by negativně but instead of the dash and two words connected together, I see an ugly white space at the beginning of the new line. Do you have any idea how to solve this problem?

I know about about a non-breaking hyphen, but please remember there is the difference between a hyphen and a dash.

**Picture**

**Right solution**

frydolin
  • 43
  • 1
  • 4
  • 2
    I think the problem is with the hyphen. Try using `‑` instead of `-`. See this question for more info: http://stackoverflow.com/questions/7691569/no-line-break-after-a-hyphen. – Cave Johnson Oct 31 '16 at 19:56
  • 1
    Voted to close as a dupe – Asons Oct 31 '16 at 19:59
  • Okay, so there is a difference between a hyphen and a dash, so then what is your actual question then? ... Please post a second image showing how it should look like – Asons Oct 31 '16 at 20:19
  • 1
    Pretty much every browser is going to break a line on a dash, hyphen, or any other punctuation. As it mentions in an answer in the [dupe-which-is-not-a-dupe](http://stackoverflow.com/questions/7691569/no-line-break-after-a-hyphen), if you don't want it to break, wrap it in an element and use `white-space: nowrap` so it doesn't wrap. – Heretic Monkey Oct 31 '16 at 20:28
  • This works how it should, a line will break when there is a dash or a hyphen, but not when using a none-breaking hyphen, so by adding a ` ` will only prevent a line break at that space, hence called _no breaking space_ ... so as a result it will break at the dash and the following ` ` is causing the ugly white space at next line beginning – Asons Oct 31 '16 at 20:28
  • I added new pic… Typographic rules for other languages are different then in english. Dash should be in the end of line not at the beginning. Please remember the hyphen and the dash are different characters. – frydolin Oct 31 '16 at 20:47
  • Posted an answer for your, which explains how to do and what can be done – Asons Oct 31 '16 at 20:48
  • makes this white space [link](http://vitlustinec.cz/no-white-space.jpg) No wrap makes only one line [link](http://vitlustinec.cz/no-wrap.png) I need this result [link](http://vitlustinec.cz/result.png) – frydolin Oct 31 '16 at 21:00

3 Answers3

4

This works how it should, a line will break when there is a dash or a hyphen, but not when using a none-breaking hyphen, so by adding a   will only prevent a line break at that space, hence called no breaking space ..

.. so as a result it will break at the dash and the following   is causing the ugly white space at next line beginning

By removing the 2:nd  , like this, it will work fine and no ugly space at next lines beginning

Some text having hyp - pen that should break after the hyphen
and another with the da – sh that should break after the dash

Fiddle demo

And if you don't want it to break, the dupe link has the answers needed, either using the non-breaking hyphen or wrap it and set the wrapper to white-space: nowrap

Dupe link: No line-break after a hyphen

Community
  • 1
  • 1
Asons
  • 84,923
  • 12
  • 110
  • 165
  • makes this white space [link](http://vitlustinec.cz/no-white-space.jpg) No wrap makes only one line [link](http://vitlustinec.cz/no-wrap.png) I need this result [link](http://vitlustinec.cz/result.png) – frydolin Oct 31 '16 at 21:01
  • @frydolin Check this fiddle: https://jsfiddle.net/7kzme44f/1/ .... the `
    ` I used was only to show two ways, one with hyphen, one with dash ... nevertheless, my posted answer work exactly as you asked, just interpret the `
    ` as a sample delimiter
    – Asons Oct 31 '16 at 21:07
  • @frydolin Updated my answer and removed the `
    `
    – Asons Oct 31 '16 at 21:21
  • Sorry, it was only mistake. Thank you! @LGSon – frydolin Dec 01 '16 at 21:02
1

The non-breaking space doesn't prevent the hyphen from being a point at which the word can break, so it effectively forces a space before and after the hyphen.

Use a non-breaking hyphen instead:

zvyšováním ceny‑ta by negativně
Quentin
  • 914,110
  • 126
  • 1,211
  • 1,335
1

I think what you want is U+2060 WORD JOINER. This is intended to suppress line breaks that may otherwise occur, without introducing any spacing.

Jeffrey L Whitledge
  • 58,241
  • 9
  • 71
  • 99