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

前端 未结 5 905
隐瞒了意图╮
隐瞒了意图╮ 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 09:07

    Use the CSS text-indent property:

    .box {
      border: 1px solid #ffffd;
      background: #fff;
      max-width: 300px;
      padding: 15px 15px 15px 45px;
    }  
    
    .box p {
      font-family: Arial, sans-serif;
      line-height: 1.5;
      margin: 0;
      text-align: justify;
      font-size: 12px;
      text-indent: -30px;
    } 

    Lorem ipsum dolor sit amet, consectetur adipisicing elit. Illo repellendus natus minima ex possimus? Pariatur odit distinctio, similique, adipisci nesciunt molestias iusto ipsa repellendus recusandae unde, enim veniam voluptatem expedita.

提交回复
热议问题