Question: I have got contentEditable `div` which each letter have own element, like: 

```
<div contenteditable="true">
    <p id="p1">
        <span id="s1">S</span>
        <span id="s2">o</span>
        <span id="s3">m</span>
        <span id="s4">e</span>
        <span id="s5">&nbsp;</span>
        <span id="s6">t</span>
        <span id="s7">e</span>
        <span id="s8">x</span>
        <span id="s9">t</span>
    </p>
</div>

```

And I am trying to justify some longer text using `text-align: justify`, but this don't work. That is strange, because `text-align: center` and `text-align: right` works. 

After that I am trying to do that using a script which adds `margin-right` to each space, but when I am writing new text into paragraph it crashes. 

How can I do that (and save `id` and other attributes in each element) using JavaScript and/or JQuery?

Answer: 
You can add one fake word at the end and make its `width:100%` and `display: inline-block`. Like this: (change width of parent according to your requirement)

```css
.justified {
  width: 300px;
  text-align: justify;
}

.justified .fake-word {
  width: 100%;
  display: inline-block;
  height: 0.1em;
}
```

```html
<div contenteditable="true">
  <p id="p1" class="justified">
    <span id="s1">S</span>
    <span id="s2">o</span>
    <span id="s3">m</span>
    <span id="s4">e</span>
    <span id="s5">&nbsp;</span>
    <span id="s6">t</span>
    <span id="s7">e</span>
    <span id="s8">x</span>
    <span id="s9">t</span>
    <span class="fake-word"></span>
  </p>
</div>
```

EDIT 1:

You can remove all span tags if you don't want space in between characters:

```
<div contenteditable="true">
      <p id="p1" class="justified">
         Some Text
        <span class="fake-word"></span>
      </p>
    </div>

```

EDIT 2: 
Also, you don't have to add .fake-word, there is another way of doing this by using pseudo-class:

```
 .justified:after {
      content: "";
      display: inline-block;
      width: 100%;
 }

```
use text-align: justify with display:flex(mandatory at times) this should work.