CSS - An alternative to  

Is there a CSS alternative to  ?

Yes, you can use the CSS property: white-space: nowrap;


An example

A text span with a normal (breaking) space will be split to insert a line break.

Scientists estimate that there are 100 billion stars in the galaxy.
Scientists estimate that there are <span class="count">100 billion</span> stars in the galaxy.
.count {
    background-color: black;
    color: white;
    border-radius: 10px;
}

A text span using white-space: nowrap; will not be split. The line break will be moved earlier in the line.

Scientists estimate that there are 100 billion stars in the galaxy.
Scientists estimate that there are <span class="count nowrap">100 billion</span> stars in the galaxy.
.count {
    background-color: black;
    color: white;
    border-radius: 10px;
}
.nowrap {
    white-space: nowrap;
}

Ads by Google


Ask a question, send a comment, or report a problem - click here to contact me.

© Richard McGrath