简体   繁体   English

如何在段落中应用“文本缩进”?

[英]How to apply the “text-indent” in paragraph?

I have a problem with "text-indent" using css, What i want is, have paragraph with 3 or more lines, with in that i want to apply the "text-indent" style for first two lines and remaining lines will become to normal alignment. 我对使用CSS的“ text-indent”有疑问,我想要的是具有3行或更多行的段落,因为我想对前两行应用“ text-indent”样式,其余行将变为正常对齐。 I have tried using CSS but i couldn't get the expected result, so can anyone help me in this. 我曾尝试使用CSS,但无法获得预期的结果,因此任何人都可以在这方面帮助我。 Thanks in advance. 提前致谢。

You could use a pseudo element with float:left to achieve this 您可以使用带float:left的伪元素来实现此目的

p:before
{
    content: '';
    display:inline-block;
    width: 20px;
    height: 30px; /* however much you need for 2 lines */
    float:left;
}

FIDDLE 小提琴

text-indent is used to apply space before each paragraph. text-indent用于在每个段落之前加上空格。 So if you want to have space for the first two lines, you could either split them in two paragraphs or to encapsulate the lines in another element (div/span) and apply margin-left or padding-left, depending on what you're looking for. 因此,如果您想为前两行留出空间,则可以将它们分成两段,也可以将行封装在另一个元素中(div / span),然后根据需要使用margin-left或padding-left寻找。

<p class="indent">This is the first line.</br>
   This is the second Line
<p/>
<p>Those are other header or text or p or something else</p>

CSS CSS

.indent {
   text-indent:50px;
}

This may help: 这可能会有所帮助:

<html>
<dl>
<dt><a href="http://www.thesitewizard.com/css/hanging-indents.shtml">Hanging Indents in CSS and HTML</a></dt>
<dd><p>This article describes how you can create hanging indents on your web pages using CSS and HTML.</p></dd>
<dd><p>This is second line of hanging index</p></dd>
<p>This is normal text line 3.</p>
</html>

for demo: http://www.compileonline.com/try_html5_online.php 演示: http : //www.compileonline.com/try_html5_online.php

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

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