Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Whitespace before some punctuation characters in French: is there a CSS way to avoid lines breaking?

For example, in this sentence, "Comment allez-vous ?", the question mark and the last word in the sentence are separated by a whitespace.

When French text is written in a column, you will often get something like this:

Elle zigzague pour empiéter sur des impostures
? Jacqueline porte chance.

The line break happens between the last word of the sentence and the question mark, which is not desirable.

Elle zigzague pour empiéter sur des
impostures ? Jacqueline porte chance.

Is there a way to solve this in pure CSS? Or do we have to manually process text and wrap the punctuation and the word in a non-breaking span?

like image 290
Brachamul Avatar asked Dec 19 '18 13:12

Brachamul


People also ask

How do you stop a line break in CSS?

The display:inline-block property is used to show an element in the inline-level block container. It converts the block of elements into an inline element. Use height and width property to set an inline element. The display property is used to prevent a line break of a list of items.

How do you prevent text from breaking in CSS?

If you want to prevent the text from wrapping, you can apply white-space: nowrap; Notice in HTML code example at the top of this article, there are actually two line breaks, one before the line of text and one after, which allow the text to be on its own line (in the code).

How do I reduce white space in CSS?

Remove white space using font-size We can also remove white space by setting parent element font-size to 0 and child elements font-size to 17px .

How do you add a white space in CSS?

In CSS, you can use either the margin or padding properties to add space around elements. Additionally, the text-indent property adds space to the front of the text, such as for indenting paragraphs.


1 Answers

Use   in HTML or white-space: nowrap; in CSS.

.sentence {
  width: 314px;
  border: 1px solid #eee;
}

.nowrap {
  white-space: nowrap;
}

.sentence > span {
  border-bottom: 1px solid darkred;
}

code {
  background-color: #ddd;
  padding: 0.2em;
}
<main>

<h3>Regular space</h3>
<p class="sentence">Elle zigzague pour empiéter sur des <span>impostures ?</span> Jacqueline porte chance.</p>

<h3>Avoid new line with non-breaking space HTML entity <code>&amp;nbsp;</code></h3>
<p class="sentence">Elle zigzague pour empiéter sur des <span>impostures&nbsp;?</span> Jacqueline porte chance.</p>

<h3>Avoid new line with CSS <code>white-space: nowrap</code></h3>
<p class="sentence">Elle zigzague pour empiéter sur des <span class="nowrap">impostures ?</span> Jacqueline porte chance.</p>

</main>
like image 82
Daniel Sixl Avatar answered Sep 20 '22 11:09

Daniel Sixl