What is the best way to indent text in a DIV when it wraps?

前端 未结 5 909
隐瞒了意图╮
隐瞒了意图╮ 2021-02-02 08:04

So I have a DIV that contains some dynamic text. Let\'s say I know the text and font-size but I don\'t know the size of the DIV. I\'d like the display of the text in the DIV t

5条回答
  •  温柔的废话
    2021-02-02 08:56

    Not sure of the cross-browser support, but you could use the first-line pseudo-element:

    p {padding:10px;}
    p:first-line {padding-left:0px;}
    
    

    Hello World, I'm Jonathan Sampson

    Would be diplayed as

    Hello World I'm
        Jonathan
        Sampson

    Other than that, you could give the element left-padding, and then a negative text-indent.

提交回复
热议问题