frydolin
frydolin

Reputation: 63

HTML non-breaking space is not working properly

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**

Upvotes: 6

Views: 8319

Answers (3)

Asons
Asons

Reputation: 87201

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

Upvotes: 4

Jeffrey L Whitledge
Jeffrey L Whitledge

Reputation: 59463

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.

Upvotes: 1

Quentin
Quentin

Reputation: 943605

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ě

Upvotes: 1

Related Questions