4

How do you wrap the text automatically? I have tried several approaches but none of them it works.

Data type for the Description field is: Rich Text Area(131072)

Visualforce page:

<apex:outputText value="{!SUBSTITUTE(description,'\n','\\\n')}"            
                      escape="false" style="white-space:pre;"/>

Controller:

 public String Description {get;set;}

in the controller constructor:

 myobject__c = /*soql*/
 Description = myboject__c.Description__c;

Screen shot:

enter image description here

7
  • Can you be more specific about what the problem is? Do you just have one super long line and need it to wrap?
    – Adrian Larson
    Commented Jan 2, 2017 at 16:24
  • I thought I explained but yes I'm looking to wrap the long line.
    – Nick
    Commented Jan 2, 2017 at 16:25
  • Try changing the white-space style to pre-wrap...
    – Adrian Larson
    Commented Jan 2, 2017 at 16:28
  • That looks like Lightning? Are you using slds-vf?
    – sfdcfox
    Commented Jan 2, 2017 at 16:34
  • @AdrianLarson: it does work :) please post that as answer
    – Nick
    Commented Jan 2, 2017 at 16:37

1 Answer 1

4

You need to set your white-space style to pre-wrap. Take a look at the CSS white-space Property:

normal
Sequences of whitespace will collapse into a single whitespace. Text will wrap when necessary. This is default

nowrap
Sequences of whitespace will collapse into a single whitespace. Text will never wrap to the next line. The text continues on the same line until a <br> tag is encountered

pre
Whitespace is preserved by the browser. Text will only wrap on line breaks. Acts like the tag in HTML

pre-line
Sequences of whitespace will collapse into a single whitespace. Text will wrap when necessary, and on line breaks

pre-wrap
Whitespace is preserved by the browser. Text will wrap when necessary, and on line breaks

initial
Sets this property to its default value. Read about initial Play it » inherit Inherits this property from its parent element. Read about inherit

1
  • 2
    Technically, the correct method is to use slds-wrap, explained here.
    – sfdcfox
    Commented Jan 2, 2017 at 16:46

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .