【问题标题】:In CSS, is there any way to add a tab break between two strings in `content`?在 CSS 中,有没有办法在“内容”中的两个字符串之间添加制表符?
【发布时间】:2021-02-01 18:54:08
【问题描述】:

在 CSS 中,有什么方法可以在 content 中的两个字符串之间添加制表符,例如 \00a0 用于 nbsp?

例如,你可以写:

div.test::before {
   content: "hello\00a0world";
}

输出hello world

但是,如果输出单词 hello 并在单词 world 之前用制表符分隔,那又如何呢?

【问题讨论】:

    标签: css text tabs special-characters pseudo-element


    【解决方案1】:

    您还需要定义空白算法

    div.test::before {
       content: "hello\09world";
       white-space:pre;
    }
    
    div.test2::before {
       content: "hello\Aworld";
       white-space:pre;
    }
    
    [class] {
      border:1px solid;
      margin:5px;
    }
    <div class="test">
    </div>
    
    <div class="test2">
    </div>

    【讨论】:

    • 啊!这就是我所缺少的!非常感谢!请注意,当我在 Firefox 中使用“运行代码 sn-p”时,您的第一个示例有效,但第二个示例导致两个字符串出现在两个单独的行上。知道为什么吗?
    • @RockPaperLz-MaskitorCasket 我使用了两个 unicode 来说明,一个用于创建选项卡(如您所愿),另一个用于创建换行符。想要显示无论您尝试添加的 空格,您都需要调整空格
    • 啊!我明白你现在做了什么以及你为什么这样做!非常感谢您的解释。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-06-15
    • 1970-01-01
    • 1970-01-01
    • 2021-05-20
    • 1970-01-01
    • 2022-12-18
    相关资源
    最近更新 更多