How to line-break from css, without using
?

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

output:

hello
How are you

code:

hello
How are you

Ho

26条回答
  •  甜味超标
    2020-11-22 16:37

    Use
    as normal, but hide it with display: none when you don't want it.

    I would expect most people finding this question want to use css / responsive design to decide whether or not a line-break appears in a specific place. (and don't have anything personal against
    )

    While not immediately obvious, you can actually apply display:none to a
    tag to hide it, which enables the use of media queries in tandem with semantic BR tags.

    The quick brown fox
    jumps over the lazy dog
    @media screen and (min-width: 20em) {
      br {
        display: none; /* hide the BR tag for wider screens (i.e. disable the line break) */
      }
    }
    

    This is useful in responsive design where you need to force text into two lines at an exact break.

    jsfiddle example

提交回复
热议问题