【问题标题】:How to indent the first line if and only if there are 2 or more lines to display?当且仅当有 2 行或更多行要显示时,如何缩进第一行?
【发布时间】:2021-12-03 06:51:18
【问题描述】:

我有一个显示纯文本的div 标记。根据文本或 div 的宽度,文本可能显示为一行或多行。

任务:

只有2行或更多行时如何缩进第一行?

【问题讨论】:

标签: javascript html css frontend


【解决方案1】:

text-indent 属性指定文本块中第一行的缩进。

div p {
  text-indent: 2em;
}

如果您只想将其应用于 div 中的第一段,您可以使用 :first-child 选择器

div p:first-child {
  text-indent: 2em;
}

【讨论】:

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