问题
How can I indent starting from the second line of a paragraph?
I've tried
p {
text-indent: 200px;
}
p:first-line {
text-indent: 0;
}
and
p {
margin-left: 200px;
}
p:first-line {
margin-left: 0;
}
and
(with position:relative;)
p {
left: 200px;
}
p:first-line {
left: 0;
}
回答1:
Is it literally just the second line you want to indent, or is it from the second line (ie. a hanging indent)?
If it is the latter, something along the lines of this JSFiddle would be appropriate.
div {
padding-left: 1.5em;
text-indent:-1.5em;
}
span {
padding-left: 1.5em;
text-indent:-1.5em;
}
<div>Lorem ipsum dolor sit amet, consectetuer adipiscing elit, sed diam nonummy nibh euismod tincidunt ut laoreet dolore magna aliquam erat volutpat. Ut wisi enim ad minim veniam, quis nostrud exerci tation ullamcorper suscipit lobortis nisl ut aliquip ex ea commodo consequat.</div>
<span>Lorem ipsum dolor sit amet, consectetuer adipiscing elit, sed diam nonummy nibh euismod tincidunt ut laoreet dolore magna aliquam erat volutpat. Ut wisi enim ad minim veniam, quis nostrud exerci tation ullamcorper suscipit lobortis nisl ut aliquip ex ea commodo consequat.</span>
This example shows how using the same CSS syntax in a DIV or SPAN produce different effects.
回答2:
This worked for me:
p { margin-left: -2em;
text-indent: 2em
}
回答3:
Make left-margin: 2em or so will push the whole text including first line to right 2em. Than add text-indent (applicable to first line) as -2em or so.. This brings first line back to start without margin. I tried it for list tags
<style>
ul li{
margin-left: 2em;
text-indent: -2em;
}
</style>
回答4:
If you style as list
I guess putting the second line in would also work, but requires human thinking for the content to flow properly, and, of course, hard line breaks (which don't bother me, per se).
回答5:
I needed to indent two rows to allow for a larger first word in a para. A cumbersome one-off solution is to place text in an SVG element and position this the same as an <img>. Using float and the SVG's height tag defines how many rows will be indented e.g.
<p style="color: blue; font-size: large; padding-top: 4px;">
<svg height="44" width="260" style="float:left;margin-top:-8px;"><text x="0" y="36" fill="blue" font-family="Verdana" font-size="36">Lorum Ipsum</text></svg>
dolor sit amet, consectetuer adipiscing elit, sed diam nonummy nibh euismod tincidunt ut laoreet dolore magna aliquam erat volutpat. Ut wisi enim ad minim veniam, quis nostrud exerci tation ullamcorper suscipit lobortis nisl ut aliquip ex ea commodo consequat.</p>
- SVG's height and width determine area blocked out.
- Y=36 is the depth to the SVG text baseline and same as font-size
- margin-top's allow for best alignment of the SVG text and para text
- Used first two words here to remind care needed for descenders
Yes it is cumbersome but it is also independent of the width of the containing div.
The above answer was to my own query to allow the first word(s) of a para to be larger and positioned over two rows. To simply indent the first two lines of a para you could replace all the SVG tags with the following single pixel img:
<img src="data:image/gif;base64,R0lGODlhAQABAIAAAP///wAAACH5BAEAAAAALAAAAAABAAEAAAICRAEAOw==" style="float:left;width:260px;height:44px;" />
来源:https://stackoverflow.com/questions/17158253/indent-starting-from-the-second-line-of-a-paragraph-with-css