What's new

Welcome to the forum 👋, Visitor

To access the forum content and all our services, you must register or log in to the forum. Becoming a member of the forum is completely free.

Preventing line wrapping within spans of text (to avoid breaking first name from surname in a list of names)

martinu

New member
Joined
Feb 16, 2026
Messages
2
Reaction score
0
HTML Coins
36
I have a paragraph which consists of lots of names (forename and surname) listed as a large block "Mike Wilson; Jill Bradshaw; Janet Thomas;" etc. I want to prevent the names breaking between forename and surname, while allowing breaking after the ";" separator.

In an HTML file I've defined a span class with "white-space: nobreak;" and each name is enclosed in <span class="nobreak">John Smith;</span>

The operative code is
<style>
<!-- when wrapping lines, don't break names between forename(s) and surname -->
span.nobreak { display: inline; white-space: nowrap; }
</style>

and
<span class="nobreak">Jane Absolom;</span>
<span class="nobreak">David Adamson;</span>


This has no effect: names still break between Jane and Absolom if they happen to occur at the end of a line.

The annoying thing is that I'm sure this used to work a year or so ago, and the only changes I've made to the page since then (AFAIK) are to add more names enclosed in span tags.

The live page is https://buckinghamshireremembers.org.uk/acknowledgements body.htm ("Individuals" section).
 
It looks as if it's a CSS problem. If I change all the <span class="nobreak"> to <span style="white-space: nowrap;"> thus making it an inline reference rather than one inherited from CSS code, everything works fine.

What embarrassingly naive syntax error have I made with my CSS?
 
Try to add this :

.nobreak {white-space:nowrap;}

You can use your browser's inspector to see if this code appears correctly in the span. Otherwise, the problem lies elsewhere.

More precisions on white-space
 
Last edited:

Theme customization system

You can customize some areas of the forum theme from this menu.

  • Wide/Narrow view

    You can control a structure that you can use to use your theme wide or narrow.

    Grid view forum list

    You can control the layout of the forum list in a grid or ordinary listing style structure.

    Picture grid mode

    You can control the structure where you can open/close images in the grid forum list.

    Close sidebar

    You can get rid of the crowded view in the forum by closing the sidebar.

    Fixed sidebar

    You can make it more useful and easier to access by pinning the sidebar.

    Close radius

    You can use the radius at the corners of the blocks according to your taste by closing/opening it.

  • Choose the color combination that reflects your taste
    Background images
    Color gradient backgrounds
Back