How to remove gaps from a given class from the end?

I need to remove   after the value of the specified intervals.
HTML looks like this:

 <span class="number">0.15&nbsp;</span> 

& nbsp; comes from the server (CMS).

Is there any way to remove & nbsp; using CSS rules?

+6
source share
4 answers

If this value is provided by your CMS, perhaps you can change the value with php via str_replace('&nbsp;', '', $yourVar) before echoing in your range.

If you do not have access to this, you can also use jQuery for this ... Like Muhammad Ali said:

 var str = $('.number').html(); str.replace('&nbsp;', ''); $('.number').html(str); 

Something like this might work. But with CSS, I'm not sure.

0
source

You cannot do this with css only. Somehow you need to use jquery for this. With regex, you can just do it.

 var span = $('span').html(); span = span.replace(/&nbsp;/g, ''); $('span').html(span); 

Demo

Note. &nbsp; comes from CMS, you need to use jquery code to replace it when your document is fully loaded.

 $(document).ready(function(){ var span = $('span').html(); span = span.replace(/&nbsp;/g, ''); $('span').html(span); }); 
+1
source

You cannot remove characters from document contents using CSS. You don’t need CSS for this. You can add symbols for visualization, generated content, but not delete.

However, you can undo character effects when rendering. Consider the following example:

 <span class="number">0.15&nbsp;</span>foo 

Empty space ( &nbsp; ) has two effects: it causes a visible distance, the same as a regular space character, and prevents line breaks between "0.15" and "foo" when the browser formats the text. To prevent the last effect, you can add normal space using the generated content, but then there will be too many intervals if a line break does not appear. To fix this, set the width of the pseudo-element to zero:

 .number:after { content: " "; display: inline-block; width: 0; } 

To remove the interval effect without a space, you can set the negative right margin. The main problem is that the width of the space without a gap (and space) depends on the font. This is an average of about a quarter of em , but it can vary significantly. If you can consider the font as fixed (for example, you use @font-face ), you can use the following code, only with a given numeric value:

  .number { display: inline-block; margin-right: -0.25em; } 

As a side effect, this can also lead to line breaks between β€œ0.15” and β€œfoo”, since browsers can handle inline blocks in formatting so that they always allow line breaks before and after.

+1
source

you can use javascript / jquery framework to remove any charackey similar to this exam Here

 var span = $('span').html(); span = span.replace('&nbsp;',''); $('span').html(span); 
0
source

Source: https://habr.com/ru/post/973351/


All Articles