CSS styling to show end of single text string

后端 未结 3 675
猫巷女王i
猫巷女王i 2020-12-11 18:27

I have a long text string. How do I get all the text to show on one line and with a certain width, but limit what is shown to the end of the string?

相关标签:
3条回答
  • 2020-12-11 19:03

    Here is a flex solution without changing direction:

    .demo {
      border: 1px solid red;
      white-space: nowrap;
      max-width: 100px;
      overflow: hidden;
      display: flex;
      justify-content: flex-end;
    }
    <p class="demo">hello this is a string</p>

    0 讨论(0)
  • 2020-12-11 19:05

    If you want the end of the string to show and hide the beginning, you can add the direction:rtl; property.

    .demo {
        border: 1px solid red;
        white-space: nowrap;
        max-width: 100px;
        overflow: hidden;
        direction:rtl;
    }
    <p class="demo">hello this is a string</p>

    0 讨论(0)
  • 2020-12-11 19:15

    .demo {
        border: 1px solid red;
        white-space: nowrap;
        max-width: 100px;
        overflow: hidden;
        direction: rtl;
    }
    <p class="demo">hello this is a string</p>

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