indent wrapped text

前端 未结 3 1726
春和景丽
春和景丽 2021-02-07 04:28

So I\'m simulating a table layout with a div and a couple spans inside it. I\'d like the span on the right to indent any text that wraps. I\'ve tried a few things and can\'t ge

相关标签:
3条回答
  • 2021-02-07 04:34

    The CSS 3 draft specifies a hanging indent. If supported by Browsers, the following should work:

    .hanging-indent
    {
      text-indent: 3em hanging each-line;
    }
    

    Unfortunately neither hanging nor each-line values are currently supported in modern browsers as the specification for CSS Text Module Level 3 is still a Draft.

    The feature is implemented with a browser specific prefix for WebKit and Chromium. For Firefox there is an open Bug you may vote on.

    0 讨论(0)
  • 2021-02-07 04:50

    Check this out: http://jsfiddle.net/2Wbuv/2/

    .display-element {
    }
    
    .display-label {
      display: inline-block;
      width: 100px;
      padding-left: 5px;
    }
    
    .display-field {
      display: inline-block;
      padding-left: 50px;
      text-indent: -50px;
      vertical-align: top;
      width: 200px; /* for testing purposes only */
    }
    <div class="display-element">
      <span class="display-label">Field 1</span>
      <span class="display-field">This is my string of data, some times it is pretty long.  Sometimes it is not.  This one is.</span>
    </div>
    <div class="display-element">
      <span class="display-label">Field 2</span>
      <span class="display-field">This is another string of data.</span>
    </div>

    0 讨论(0)
  • 2021-02-07 04:51

    It sounds like you want a hanging indent. CSS something like this should do the trick:

    .hanging-indent
    {
      text-indent : -3em ;
      margin-left :  3em ;
    }
    

    But since your <span> is an inline element, the text-indent property, as well as other CSS properties pertaining to a block, is meaningless.

    0 讨论(0)
提交回复
热议问题