Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

CSS multiple spaces inside span element

I have a page where I am trying to display full name (firstName lastName) on the browser.

In my JSP, I have

<span>
    <c:if test="${someCondition1}">
        <c:out value="${firstName}">
    </c:if>
    <c:if test="${someCondition2}">
        <c:out value="${lastName}">
    </c:if>
</span>

Now there are some code indentation spaces inside the span element. The issue is that in Firefox, the code spaces are not collapsed, while IE collapses them.

Also I tried using the various CSS white-space properties ;normal, wrap, -moz-pre-wrap, etc

But this does not seem to be working for some reason.

Also I might not be able to use the white-space property to fix this, since I can have multiple spaces within the firstName/lastName as well which should be displayed as it is e.g. first Name can be

"my    First   Name"

Thus using CSS white-space on the span element to collapse multiple spaces would be wrong.

like image 636
copenndthagen Avatar asked Mar 31 '26 17:03

copenndthagen


1 Answers

You can replace your spaces with &nbsp;

firstName = firstName.replace(" ", "&nbsp;");

With this you don't need your CSS white-space anymore.

like image 143
PiTheNumber Avatar answered Apr 03 '26 16:04

PiTheNumber



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!