I am adding a span elements dynamically from input field into a div. When they reached the right end of the div. It overflows in the same line.
However, when the number of span elements are pre-defined into a div element then they are not overflowed and they comes down and starts from a new line. I want this way.
I analysed both the element structure in firebug and both look same.
Here the fiddle for demonstration – FIDDLE
Please let me know for any mistake I am doing and if there is any workaround.
Since
spanis an inline element, it’s affected by whitespace in the HTML.In your predefined example, you have a line break between each
span.To make your JavaScript version work, you need to add some whitespace.
Add either a line break:
or just a space:
The choices are equivalent, but your intention may be clearer with a line break.