Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

format string with wider space between specific chars

How to format a barcode EAN13 string with CSS and add wider space between specific char/digits? Want to add wider space after char 1 and char 7

https://boxshot.com/barcode/tutorials/ean-13-calculator/ean-13-barcode-check-digit.svg

Right now I use this function to format the string

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

function format_barcode_ean13(v){
    return `<div style="display:inline-flex; gap:4px">
    <div>${v.substring(0, 1)}</div>
    <div>${v.substring(1, 7)}</div>
    <div>${v.substring(7, 13)}</div>
</div>`;
}

But when using the above function you can’t double click on the string to select the entire string. Only the group (flex item) is selected.

I need to be able to apply the wider space between chars and still be able to double click and then select everything

>Solution :

You can set letter-spacing for individual characters and produce wider gaps before them:

<p>12<span style="letter-spacing: 2em;">3</span>45<span style="letter-spacing: 2em;">6</span>789</p>

This way it will remain a "single word" for double click selection.


Alternatively it is possible to use empty inline-blocks, but they break whole-word selection in Firefox:

<p>123<span style="display: inline-block; width: 2em"></span>456<span style="display: inline-block; width: 2em"></span>789</p>
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading