段落第一行后的文本缩进
- 楠格哈尔省苏克罗德地区的一名路透社记者称,袭击发生在该地区,村民称袭击发生在当地,并称在一些人开始向当地政府大楼投掷石块后,阿富汗警方向人群开枪。
在上面的段落中,我想使用 CSS 使第一行之后的所有行自动缩进一些空格,以便每一行都保留在第一行中的 - 之后。
HTML
<p> - A Reuters reporter in Surkhrod district in Nangarhar province, where
villagers said the raids took place, said Afghan police fired at the crowd
after some of them started throwing stones at local government buildings.</p>
它类似于列表位置设置为外部的列表项,但我不想使用列表。
您能想到实现这种效果的最简单方法是什么?额外的 html 标记越少越好。
非常感谢大家。
- A Reuters reporter in Surkhrod district in Nangarhar province, where villagers said the raids took place, said Afghan police fired at the crowd after some of them started throwing stones at local government buildings.
In the above paragraph, I would like to use CSS to make all lines after the first line to automatically indent some space so that each line stays right after the - in the first line.
HTML
<p> - A Reuters reporter in Surkhrod district in Nangarhar province, where
villagers said the raids took place, said Afghan police fired at the crowd
after some of them started throwing stones at local government buildings.</p>
It's similar to a list item with list position set to outside, but I don't want to use a list.
What is the simplest way you can think of to achieve this effect? Less extra html markups will be better.
Many thanks to you all.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
您需要
text-indent
。通常text-indent
会将第一行向内推,但如果你给它一个负数并使用正边距,你就可以达到你想要的效果。You need
text-indent
. Normallytext-indent
pushes the first line inwards, but if you give it a minus figure and use a positive margin, you can achieve the effect you're after.目前不可用,但如果您在 Chrome 上激活“实验性 Web 平台”标志(通过转到
chrome://flags/#enable-experimental-web-platform-features
),您可以使用text-indent:1em every-line;
这应该完全符合你的要求。MDN 上的文本缩进
Not usable right now but if you activate the "Experimental Web platform" flag (by going to
chrome://flags/#enable-experimental-web-platform-features
) on Chrome you can usetext-indent:1em each-line;
which should do exactly what you want.text-indent on MDN
我注意到,在内联元素上它的工作方式可能有所不同。我需要一个“outdent”(第一行比段落其余部分更左边),并注意到上面的建议做了相反的事情——创建了一个常规缩进(其中第一行比其他行更右边)。以下是适用于内联元素的内容,例如“a”标签:
我还将包含的块级元素设置为具有 1em 的边距,以便内联“a”元素开始的位置具有负边距,他们实际上准确地定位了我在乱搞“突出”之前原本应该放置的位置。
希望这对某人有帮助!我还注意到我的内联元素上的文本缩进本身没有大小控制......
JSFiddle 示例< /a>
On inline elements maybe it works differently, I have noticed. I was needing an "outdent" (first line further left than rest of paragraph) and noticed the suggestions above did the opposite -- created a regular indent (where first line is further RIGHT than other lines). Here is what works for an inline element, for example, an "a" tag:
I also set the containing block-level element to have a margin of 1em, so that where the inline "a" elements commence, with their negative margins, they actually position exactly where I things would have been originally before messing around to make an "outdent".
Hope this helps someone! I also noticed there's no size control on the text-indent itself on my inline element, either....
JSFiddle Example
以@kennytm 的答案为基础;如果要对齐等宽文本,请使用
ch
单位而不是em
单位。例如:使用基于
ch
的填充/负缩进将呈现(基于页面宽度)为:
Building on @kennytm's answer; if you want to align monospaced text, use
ch
units instead ofem
units. For example:with
ch
-based padding/negative indentsWill render (based on page width) as: