How to line-break from css, without using
?

后端 未结 26 1640
攒了一身酷
攒了一身酷 2020-11-22 15:49

output:

hello
How are you

code:

hello
How are you

Ho

26条回答
  •  星月不相逢
    2020-11-22 16:18

    There are several options for defining the handling of white spaces and line breaks. If one can put the content in e.g. a

    tag it is pretty easy to get whatever one wants.

    For preserving line breaks but not white spaces use pre-line (not pre) like in:

    
    
    

    hello How are you

    If another behavior is wanted choose among one of these (WS=WhiteSpace, LB=LineBreak):

         white-space: normal;   /* collapse WS, wrap as necessary, collapse LB */
         white-space: nowrap;   /* collapse WS, no wrapping,       collapse LB */
         white-space: pre;      /* preserve WS, no wrapping,       preserve LB */
         white-space: pre-wrap; /* preserve WS, wrap as necessary, preserve LB */
         white-space: inherit;  /* all as parent element */
    

    SOURCE: W3 Schools

提交回复
热议问题