-1

I am getting dynamic variable from webservice. I want to add the empty space or breaktag tag in the javascript variable.

For eg:

let myVal = "myname 123456789 NZD".

when displaying in the UI I want to display the names like below in a single div

myname 
123456789
NZD

The variable name all are dynamic. I am using word-wrap: break-word.

But few text cut of eg:

firstname last
name 123456789.

How to achieve like below :

myname 
123456789 
NZD

I am using below css:

div{
    position: relative;
    top: 5px;
    left: 10px;
    width: 46%;
    min-height: 22px;
    height: auto;
    font-family: "Montserrat-SemiBold";
    font-size: 15px;
    font-weight: 600;
    font-stretch: normal;
    font-style: normal;
    line-height: 1.47;
    letter-spacing: normal;
    color: #000000;
    padding-bottom: 11px;
    word-wrap: break-word;
}

3 Answers3

0

Try this

<div class="one-word-each-line" style="
    width: min-intrinsic;
    width: -webkit-min-content;
    width: -moz-min-content;
    width: min-content;
    display: table-caption;
    display: -ms-grid;
    -ms-grid-columns: min-content;
">myname 123456789 NZD</div>
Nitesh Phadatare
  • 305
  • 1
  • 2
  • 12
0

When you're using ember I could use a computed property in combination with a {{#each}} loop producing <br> tags:

so a computed property in your component or controller like this:

splittedValue: computed('myVal', function() {
  return this.myVal.split(' ');
}),

and then this in the template:

<div>
  {{#each this.splittedValue as |line|}}
    {{line}}<br>
  {{/each}}
</div>
Lux
  • 17,140
  • 4
  • 38
  • 70
-1

Check this out. Dynamic and reusable.

 function createWrapper(value) {
  const wrapper = document.createElement("div");
  wrapper.classList.add("wrapper");
  value.split(" ")
       .forEach(v => {
        const span = document.createElement("span");
        span.innerText = v;
        wrapper.appendChild(span);
        });
  document.getElementById("container").appendChild(wrapper);
 }
 createWrapper("Alex 575 ASD");
 createWrapper("Siya 666 ABC");
 createWrapper("Jack 090 XYZ");
.wrapper {
  border: 1px solid black;
  display: flex;
  flex-direction: column;
 }    
 <div id="container">
 </div>
PatMan10
  • 501
  • 1
  • 5
  • 15