简体   繁体   English

如何使用 CSS 在 BR 标记后添加 em 空格()

[英]how to add em space ( ) after BR tag using CSS

I want to add an em-space just after BR tag so as to achieve text-indent effect.我想在 BR 标签之后添加一个 em-space 以实现文本缩进效果。 But the following STYLE doesn't work on my Chrome.但以下 STYLE 不适用于我的 Chrome。

Or, any other way to achieve text-indent effect after BR tag?或者,还有什么其他方法可以在 BR 标签之后实现文本缩进效果?

<style>
br::after { 
  content: "&emsp;";
}
</style>

<p>Note:<br>For this selector to work in IE8, a DOCTYPE must be declared, and you must use the old, single-colon CSS2 syntax (:after instead of ::after).</p>

You really shouldn't be using a line break (br) tag to break up paragraphs, not in modern web design.在现代 web 设计中,您真的不应该使用换行符 (br) 标签来分隔段落。 See the HTML 5.2 spec for some examples.有关示例,请参阅HTML 5.2 规范

Furthermore, there is a CSS property text-indent which also achieves the text indentation you are after.此外,还有一个 CSS 属性text-indent也可以实现您所追求的文本缩进。

Basically, use <p> as intended (eg to wrap a paragraph) and then apply text-indent to the p tags.基本上,按预期使用<p> (例如,换行),然后将text-indent应用于p标记。

 p { text-indent: 1em; } p.unindented { text-indent: inherit; }
 <p class="unindented">Note:</p> <p>For this selector to work in IE8, a DOCTYPE must be declared, and you must use the old, single-colon CSS2 syntax (:after instead of::after).</p> <p>Here is another paragraph to show how this applies when you have more than one &lt;p&gt; of content. The text-indent property is supported by all major browsers. (That is, IE 3 and later. Not that IE is a major browser anymore....)</p> <p>See here for more info: https://developer.mozilla.org/en-US/docs/Web/CSS/text-indent</p>

text-indent is a very old property with wide support across all major browsers and a lot of older ones too. text-indent是一个非常古老的属性,在所有主流浏览器和许多旧浏览器中都有广泛的支持。 It was first introduced in IE 3, to give a sense of how old it is.它最初是在 IE 3 中引入的,以了解它的历史。 See MDN for more information.有关更多信息,请参阅MDN

I managed to do this to add an em space just after BR tag!我设法做到这一点,在 BR 标签之后添加一个 em 空间!

<style>
br {
  content: '';
  white-space: pre;
}

br::after { 
  content: "\A\2003";
}
</style>

Another problem is that I also want to keep 1em margin-bottom.另一个问题是我还想保持 1em 的边距底部。 The following style ALONE works well.以下样式 ALONE 效果很好。

<style>
br {
  content: '';
  display: block; 
  margin-bottom: 1em; 
}
</style>

BUT, if i mixed the two styles into the following, it doesn't work!!!但是,如果我将两个 styles 混合到下面,它不起作用!!!

<style>
br {
  content: '';
  white-space: pre;
  display: block; 
  margin-bottom: 1em; 
}

br::after { 
  content: "\A\2003";
}
</style>

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

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