简体   繁体   English

如何缩进段落中除第一行之外的所有文本?

[英]How can I indent all text in a paragraph except the first line?

This is an example fiddle .这是一个示例小提琴

What I'm trying to do is indent everything after the first line.我想要做的是在第一行之后缩进所有内容。

Right now it looks like:现在它看起来像:

Categories: Aperiri 
nostrum similique cu 
pro, maiorum delectus 
quo eu. Mentitum

I'm trying to get it to look like:我试图让它看起来像:

Categories: Aperiri 
  nostrum similique cu 
  pro, maiorum delectus 
  quo eu. Mentitum

I've tried adding to the css:我试过添加到 css:

display: block;
margin: 2px;

But this screws up my text wrapping.但这搞砸了我的文字换行。

How can I have inline display but also indent after the first line in css?如何在 css 中的第一行之后进行内联显示和缩进?

You can use the text-indent property with a negative value and compensate it with a left margin.您可以使用负值的text-indent属性并用左边距补偿它。

For instance:例如:

.negative-indent {
    margin-left: 40px;
    text-indent: -40px;
}

Reference for text-indent property: MDN text-indent属性参考: MDN

Use :first-line and text-indent tag.使用:first-linetext-indent标签。 Put your whole text in one block (div or paragraph).将整个文本放在一个块(div 或段落)中。 Indent all lines and then set the first line to text-indent = 0缩进所有行,然后将第一行设置为text-indent = 0

Example:例子:

p { text-indent: -10px }
p:first-line { text-indent: 0 }

How about this:这个怎么样:

.hClass p{
    padding-left: 20px;
}


.iClass{
    font-style: oblinque;
    color: rgb(136, 136, 136);
    font-family: Arial,Liberation Sans,DejaVu Sans,sans-serif;
    margin-left: -20px;
}

See: http://jsfiddle.net/gVJK8/5/见: http : //jsfiddle.net/gVJK8/5/

I had the same problem.我有同样的问题。 The answers published here until now gave me a bad result (letters were overlapping each other) when complex layout (eg tables) was present in the paragraph being undented.到目前为止,当段落中存在复杂的布局(例如表格)时,此处发布的答案给了我一个糟糕的结果(字母相互重叠)。

After much trying I found that the following didn't mess with these.经过多次尝试,我发现以下内容与这些无关。

text-indent: 0.5em hanging;

Only tried it in Chrome.只在 Chrome 中尝试过。

我发现最好使用这样的简单解决方案:

p:nth-child(n+2){text-indent: 3px;}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM