-1

enter image description here

I am having one message box in which I am having one div with some text. I am passing "1 am khushbu/n happy new year". It is not considering /n as command. ..It is taking it as text. I want that if I write:

"hello
I
am
"

It should be printed in next line. used also. I am using this style :

<div id="Stage_Scrolls_MessageBox_message_box_Text"
     class="Stage_Scrolls_MessageBox_message_box_Text_id" 
     style="position: absolute; 
            margin: 0px; 
            left: 12.61%; 
            top: 23.18%; 
            width: 165px; 
            height: 157px; 
            right: auto; 
            bottom: auto; 
            font-family: abel; 
            font-size: 21px; 
            font-weight: 400; 
            color: rgb(166, 33, 36); 
            text-decoration: none; 
            font-style: normal; 
            word-wrap: break-word; 
            text-align: center; 
            -webkit-tap-highlight-color: rgba(0, 0, 0, 0); 
            -webkit-transform: translateZ(0px); 
            line-height: 25px; 
            letter-spacing: 0px;">
      During this Season may the joy and love of &lt;/br&gt; Christmas be yours.
</div>
Mardzis
  • 760
  • 1
  • 8
  • 21
Curious_k.shree
  • 990
  • 2
  • 18
  • 37
  • Use `
    ` tags instead.
    – Weafs.py Dec 30 '14 at 06:33
  • my text is not taking commands.../n or .On console it is showing my text in next line but on view..it is not showing me in next line – Curious_k.shree Dec 30 '14 at 06:34
  • You're Welcome! :) ----> http://jsfiddle.net/wufx69pb/ – Weafs.py Dec 30 '14 at 06:36
  • Or you could use CSS's `word-spacing` property if you have more text. http://jsfiddle.net/wufx69pb/1/ – Weafs.py Dec 30 '14 at 06:42
  • 1
    you can try using a pre tag http://jsfiddle.net/wufx69pb/2/ – Vitorino fernandes Dec 30 '14 at 07:13
  • NO..this is dynamic run-time operation which I want to do...Whenever system recognize /n in text , rest of the text should go in next line – Curious_k.shree Dec 30 '14 at 07:15
  • The text needs a break tag. The text of the above DIV tag instead of using a break tag, uses this "</br>" which renders the right and left angle brackets without any HTML meaning. Also, the break tag should not be written as ""; write the tag as
    (see http://www.w3schools.com/tags/tag_br.asp).
    – slevy1 Dec 30 '14 at 07:30
  • 2
    Looks like your templating framework is encoding your html? Or you are running some sort of html entities encoding function on your text there. That's probably why your break tag does not work. – Gohn67 Dec 30 '14 at 07:38
  • You may want to take a look at this answer: http://stackoverflow.com/questions/14963444/angularjs-is-rendering-br-as-text-not-as-a-newline – Gohn67 Dec 30 '14 at 08:24

5 Answers5

1

Check This: The working solution

please replace &lt;/br&gt; with <br/>

 <p id="Stage_Scrolls_MessageBox_message_box_Text" class="Stage_Scrolls_MessageBox_message_box_Text_id" style="position: absolute; margin: 0px; left: 12.61%; top: 23.18%; width: 165px; height: 157px; right: auto; bottom: auto; font-family: abel; font-size: 21px; font-weight: 400; color: rgb(166, 33, 36); text-decoration: none; font-style: normal; word-wrap: break-word; text-align: center; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); -webkit-transform: translateZ(0px); line-height: 25px; letter-spacing: 0px;">During this Season may the joy and love of <br/> Christmas be yours.</p>
Madhu
  • 2,643
  • 6
  • 19
  • 34
0

Use <br /> tag or give a specific width for the div.

Jaison James
  • 4,414
  • 4
  • 42
  • 54
0

Try this:

<div>I am Khushbu Happy New Year</div>

CSS

div {

width: 5em;

}

Change The width according to your Requirement.

You can Try like this as well,

 <p>I am Khushbu, <br/> Happy New Year</p>
Madhu
  • 2,643
  • 6
  • 19
  • 34
  • my issue is : it is not taking
    or on view
    – Curious_k.shree Dec 30 '14 at 07:04
  • @Curious_k.shree use

    tag instead of

    – Madhu Dec 30 '14 at 07:10
  • @Curious_k.shree please check my another answer, its working. – Madhu Dec 30 '14 at 07:23
  • @Curious_k.shree its working please check this [link](http://jsfiddle.net/wufx69pb/3/) – Madhu Dec 30 '14 at 07:30
  • @Curious_k.shree after using the

    tag change this **</br>** to this **
    **

    – Madhu Dec 30 '14 at 07:32
  • yes...but may be this is not an issue : my issue is i am getting "khushbu </br> temp" as div content....here,
    is not taking in consideration as command. it is taking it as string..from console , if I do "edit as html" for that div , it is showing me "</br>" instead of
    ..If I replace "</br>" with
    from element view , it is taking perfectly
    – Curious_k.shree Dec 30 '14 at 10:45
  • @Curious_k.shree what is the purpose of using **</br>** when you can directly use **
    ** it's straight forward.
    – Madhu Dec 30 '14 at 12:01
  • @Curious_k.shree **
    ** --> This is the proper syntax and you can't replace it with **html-Character-Entities**.
    – Madhu Dec 30 '14 at 12:06
  • Got solution..added above...thanks for your help..really helped me a lot . – Curious_k.shree Dec 30 '14 at 12:27
  • @Curious_k.shree you are welcome. please vote my answers, if u find it helpful :) – Madhu Dec 30 '14 at 12:29
0

Edit 1

Since you are using AngularJS, it looks like AngularJS is where you need to look. There is something encoding your html entities to prevent XSS.

See this answer for some solutions: AngularJS is rendering <br> as text not as a newline


Previous Answer

I don't know what language or framework you are using, but you should check that your templating engine is not encoding your text. That's what looks to be happening here. Most templating engines will automatically encode html entities as a security precaution. There is a way to prevent the encoding by marking your output as safe.

If you are not using a templating engine. Maybe you are using PHP and are using htmlentities function, which will convert<br/> to &lt;br/&gt;. This is a good thing to do if you are displaying user input. It will help prevent XSS (cross-site scripting attempts).

In this case it looks like you are accepting user text, so you may want to do something like run htmlentities or equivilant and then do a string replace for \n and replace with <br /> tag. In php you could use nl2br.

If you're using a templating engine, there is likely a way to do something similar as well.

Community
  • 1
  • 1
Gohn67
  • 10,608
  • 2
  • 29
  • 35
  • yes....just found thi solution...it is taking
    as <br/>. and it is not taking it as command..it is taking it as text.....for space we are using &nbsp . for what should we use? nl2br is not working
    – Curious_k.shree Dec 30 '14 at 07:52
  • Are you using a templating engine or framework? And if so which one? That would help others provide are more specific answer. – Gohn67 Dec 30 '14 at 07:53
  • I am using designing my view in adobe edge and using simple html pages..no other frameworks – Curious_k.shree Dec 30 '14 at 07:58
  • 1
    I've never used it Adobe Edge. You may want to edit your answer to show that information since it may be important. – Gohn67 Dec 30 '14 at 08:01
  • i think it's not that much important..issue is my
    something <br/>xyz
    .. Here , my <br/> should be replaced with
    tag....Trying this
    – Curious_k.shree Dec 30 '14 at 08:03
  • Can you describe how you are entering the text? Are you using the `text` tool? – Gohn67 Dec 30 '14 at 08:07
  • I am having textarea : – Curious_k.shree Dec 30 '14 at 08:11
  • So the user writes their text on the page in a text area? Or is that some widget in Adobe Edge? – Gohn67 Dec 30 '14 at 08:13
  • Thanks, it make sense now what you are doing. You are using AngularJS and outputting the user text to the div there. – Gohn67 Dec 30 '14 at 08:17
  • hm...So is there any solution? – Curious_k.shree Dec 30 '14 at 08:18
  • Yes. I don't use AngularJS, so I can't help too much. You may want to delete this question and ask the question again. Mention that you are using AngularJS and then provide some code to how you are transferring text from text area to div. You are using `ngSanitize`? – Gohn67 Dec 30 '14 at 08:20
  • You will want to replace `\n` with `
    ` but exclude br tag from ngsanitize maybe?
    – Gohn67 Dec 30 '14 at 08:21
-1

I got solution .

Solution : It is working now....We were setting text in div..Instead of that , we should set html ..So that it can set in dom

textField[0].innerHTML = textconfig.text.replace(/\r\n|\r|\n/g, "<br />");
Curious_k.shree
  • 990
  • 2
  • 18
  • 37
  • Please don't add "thank you" as an answer. Instead, vote up the answers that you find helpful. – Kartoch Dec 30 '14 at 13:08
  • @Kartoch - I have found answer by my own...with help of these guys who had helped me to give hints..So done that...anyways..thanks – Curious_k.shree Dec 30 '14 at 13:10