【问题标题】:CSS text-indent combined with white-spaceCSS文本缩进结合空白
【发布时间】:2012-05-11 19:04:34
【问题描述】:

我已经有了以下样式:white-space: pre-wrap;

这允许将换行符视为元素的换行符(并且空格不会折叠)。

现在我想申请 text-indent: -40px; padding-left: 40px; 以尝试产生这样的东西:

This is a long line of text (or at least, just pretend it is) so it  
        will indent when it wraps.
Further lines of text appear as normal, but again if they exceed the
        maximum width then they wrap and indent.

不幸的是,它并没有达到我的预期:

This is a long line of text (or at least, just pretend it is) so it
        will indent when it wraps.
        Further lines of text appear as normal, but again if they
        exceed the maximum width then they wrap and indent.

有没有办法在 CSS 中缩进换行,但将换行算作新的第一行?

【问题讨论】:

  • 如果换行符表示为单独的元素,对我来说效果很好。 jsfiddle.net/gNVgQ
  • @jessegavin 但他们不是,这就是white-space: pre-wrap 的全部意义所在。
  • 你能把每一行都换成<div>吗?然后你可以使用text-indentpadding-left

标签: css text-indent


【解决方案1】:

不,因为text-indent 与元素的第一行相关,并且换行生成的换行符不会创建元素。因此,您需要使用一些内容标记,而不仅仅是 HTML 源代码中的换行符。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2020-02-04
    • 1970-01-01
    • 2012-01-30
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多